gRAN icon indicating copy to clipboard operation
gRAN copied to clipboard

normalizePath2 makes incorrect assumptions about path names in Windows

Open andrie opened this issue 10 years ago • 2 comments

The package vignette fails in windows, in the step makeSingleGRANRepo().

I traced the first problem to normalizePath2(), where the code makes some assumptions about path names that don't seem to hold for Windows.

Reproducible example:

repdir = file.path(tempdir(), "repos")
> normalizePath2(repdir)
[1] "C:/Users/Andrie/Documents/GitHub/gRAN/C:\\Users\\Andrie\\AppData\\Local\\Temp\\RtmpszdDv8/repos"

Note the ..../gRAN/C::\\Users\\...

If I rewrite normalizePath2() by commenting out four lines toward the bottom, this problem goes away on Windows, but I don't know what the impact will be on other operating systems.

normalizePath2 = function(path, follow.symlinks=FALSE)
{
  if(follow.symlinks)
    normalizePath(path)
  else {
    path <- path.expand(path)
    fileSep <- .Platform$file.sep
    wd <- getwd()
    if(substr(path, 1, 1) == "~")
      path = path.expand(path)
    ##paths starting with / for example
    else if(substr(path, 1, 1) == fileSep)

      path  = path
    else if (substr(path, 1, 2) == "..") {
      tmppath = wd
      while(substr(path, 1, 2) == "..") {
        tmppath = dirname(tmppath)
        path = substr(path, 3, nchar(path))
        if(substr(path, 1, 1) == fileSep)
          path = substr(path, 2, nchar(path))
      }
      path = file.path(tmppath, path)
    } 
#     else if(grepl("^\\.*[[:alnum:]]", path))
#       path = file.path(wd, path)
#     else if (substr(path, 1,1) == ".")
#       path = file.path(wd, substr(path,2, nchar(path)))
    path = gsub(paste(rep(fileSep, 2), collapse=""), fileSep, path, fixed=TRUE)
    path

  }
}

andrie avatar Jun 13 '14 08:06 andrie

@andrie Thanks for your report. I should have been more clear on this, e.g. in the readme, but official support on windows is currently limited to the package installation gRAN machinery.

The repository-based stuff has been tested on Mac and Linux. Are you hoping to build a repository on a windows-based machine, or do you just want to use the sessionInfo-based reproducibility stuff?

gmbecker avatar Jun 13 '14 13:06 gmbecker

@andrie I have pushed a largely untested patch that will have normalizePath2 simply call normalizePath if R thinks it's on a Windows machine.

gmbecker avatar Jul 10 '14 15:07 gmbecker