Bug 14884 - Invalid handling of UNC paths in .libPaths()
Invalid handling of UNC paths in .libPaths()
Status: RESOLVED FIXED
Product: R
Classification: Unclassified
Component: Windows GUI / Window specific
R 2.14.1
ix86 (32-bit) Windows 32-bit
: P5 normal
Assigned To: R-core
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-04-17 13:09 UTC by Zsolt Cserna
Modified: 2012-04-19 19:48 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Zsolt Cserna 2012-04-17 13:09:59 UTC
When specifying UNC paths to .libPaths(), it doesn't handle them correctly.

Example:

> .libPaths()
[1] "M:/dist/R/PROJ/core/2.14.1-0/library"
> .libPaths(c("\\\\server\\dir\\lib", .libPaths()))
> .libPaths()
[1] "M:/dist/R/PROJ/core/2.14.1-0/library"

As you can see, the path was not added to the search path, however the path exists.

I looked into the source, and I realized that the problem caused by the following line in .libPaths():

            new <- Sys.glob(path.expand(new))

...as Sys.glob removes the path entries starting with double-backslash (it might be also true for paths starting with single backslash).

I tried to add a path having forward slashes at the beginning. At first look it seems ok:

> .libPaths(c("//server\\dir\\lib", .libPaths()))
> .libPaths()
[1] "\\\\server/dir/lib"
[2] "M:/dist/R/PROJ/core/2.14.1-0/library"  

But it changes the slashes (the first two forward-slashes become backslashes, and the backslashes in the path become forward-slashes).

It's due to a line which was introduced recently (in 2.13):


            paths <- unique(normalizePath(c(new, .Library.site, .Library), '/'))

Prior 2.13 it was:

            paths <- unique(path.expand(c(new, .Library.site, .Library)))

As normalizePath changes the first slashes, it become impossible to add new path entries to .libPaths() while keeping the old entries:

> .libPaths(c("//server\\dir2\\lib", .libPaths()))
> .libPaths()
[1] "\\\\server/dir2/lib"
[2] "M:/dist/R/PROJ/core/2.14.1-0/library"  

Note that the path which was added before ("\\\\server/dir/lib") was removed by Sys.glob.

Currently we use R 2.12 and it works correctly (adding path entries starting with forward slashes), but with R 2.14 it fails.

IMHO there could be two possible solutions:
- fixing Sys.glob to properly handle paths starting with backslash
- fixing .libPaths() by removing the normalizePath call

Please advise.
Comment 1 Duncan Murdoch 2012-04-19 19:48:03 UTC
The bug was in Sys.glob, which I think I have fixed.  (It shouldn't remove paths with the double backslash.)

There may also be a bug in file.info or normalizePath, but I don't have the energy to go after those.  For the record:  after my fix, I can set .libPaths as

.libPaths("\\\\localhost/c$/temp")

and it is fine, but

.libPaths("\\\\localhost/c$")

.libPaths("\\\\localhost/c$/")

both fail, because file.info() doesn't think the first is a directory, and normalizePath() changes the second into the first.

The Sys.glob() fix will be committed soon.  It only affects Windows systems.