Giter VIP home page Giter VIP logo

Comments (15)

eddelbuettel avatar eddelbuettel commented on August 17, 2024

Yes indeed it should. I must have busted that when generalizing for git(hub) use. We need to look at srcdir and repodir -- do you have a few spare cycles to look at it?

from drat.

shabbychef avatar shabbychef commented on August 17, 2024

I'll give it a try; my inner perl hacker (ugh) says to rewrite

file.copy(file.path(curwd, file), srcdir, overwrite=TRUE)

as

file.copy(file.path(curwd, file), srcdir, overwrite=TRUE) || file.copy(file, srcdir, overwrite=TRUE)

from drat.

shabbychef avatar shabbychef commented on August 17, 2024

oh, and maybe wrap that all with stopifnot.

from drat.

eddelbuettel avatar eddelbuettel commented on August 17, 2024

I'd pre-test with

if (!file.exists(file))  {  whine() }

etc

from drat.

shabbychef avatar shabbychef commented on August 17, 2024

There is already a check for the file at the head of the function.

from drat.

eddelbuettel avatar eddelbuettel commented on August 17, 2024

It's not quite right.

    stopifnot(file.copy(file.path(curwd, file), srcdir, overwrite=TRUE) || 
                        file.copy(file, srcdir, overwrite=TRUE))

If we are in curwd, then both branches are equivalent, so this does not yet help enough. I'll look at it some more on the train home in a few hours.

from drat.

gaborcsardi avatar gaborcsardi commented on August 17, 2024

It might help if you convert the path to absolute in the first place. E.g.

absolute_path <- function(path) {
  path <- path.expand(path)
  if (substr(path, 1, 1) == "/") {
    path
  } else {
    file.path(getwd(), path)
  }
}

Btw. why can't you just say file.copy(file, srcdir, ...)? I haven't read the complete code, so maybe this is not an option.

from drat.

eddelbuettel avatar eddelbuettel commented on August 17, 2024

Nice idea, thanks.

It should actually be pretty simple. file.copy() surely takes anything, absolute or relative, but I need a partial path later in the (optional) git2r::add() call, and that is where I went off the road prior to 0.0.2.

from drat.

eddelbuettel avatar eddelbuettel commented on August 17, 2024

The file.copy(file.path(curwd, file), srcdir) is wrong, and it arose because of the optional setwd() earlier.

from drat.

shabbychef avatar shabbychef commented on August 17, 2024

I'm not sure both "both branches are equivalent":

> file.path(getwd(),'/tmp/foobar.tar.gz')
[1] "/home/spav//tmp/foobar.tar.gz"

but you're right, I forget to fix the git2r::add.

from drat.

eddelbuettel avatar eddelbuettel commented on August 17, 2024

The stopifnot( ... || ...) is still weird, and I don't like it. We are in curwd, so both are the same. At the most, use explicit tests and stop() calls.

The basename() looks good.

from drat.

eddelbuettel avatar eddelbuettel commented on August 17, 2024

Ack re your comment of both branches being different. The problem was the thinko related to the earlier setwd(). At that point all we need is file.copy(file, dir) having tested that both file and dir exist.

from drat.

eddelbuettel avatar eddelbuettel commented on August 17, 2024

This may actually be much less scary than we thought. Can you look at what I just committed? Either via checkout, or by simply pulling the relevant file as is ?

from drat.

shabbychef avatar shabbychef commented on August 17, 2024

LGTM for absolute paths.

Should there be a catch on file.copy returning `FALSE`` (e.g. due to permissions issues)?

from drat.

eddelbuettel avatar eddelbuettel commented on August 17, 2024

Great, and a) sorry for the earlier runaround and b) yes that is a very good idea. Help page suggest that a boolean is returned to lemme add that.

from drat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.