Bug 14669 - [PATCH] Cache files used by installed.packages() are not long filename safe
[PATCH] Cache files used by installed.packages() are not long filename safe
Status: CLOSED FIXED
Product: R
Classification: Unclassified
Component: Misc
R-devel (trunk)
All Linux
: P5 normal
Assigned To: R-core
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-09-07 03:10 UTC by Murray Stokely
Modified: 2011-09-26 07:36 UTC (History)
0 users

See Also:


Attachments
Patch to utils/R/packages.R to support longer libPaths in installed.packages() (862 bytes, patch)
2011-09-07 19:00 UTC, Murray Stokely
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Murray Stokely 2011-09-07 03:10:57 UTC
The code in src/library/utils/all.R for installed.packages() assumes that :

nchar(URLencode(large path of size PATH_MAX)) + 99 < NAME_MAX

which is not true on any platform.

Specifically, it creates a temporary cache file by URL encoding a directory name and replacing path separating '/' characters to make one long filename, and adding up to 99 other characters ("libloc_" prefix, .instPkgFields, and ".rds")

On my Linux system with NAME_MAX==255 and PATH_MAX==4096, this leaves only 156 characters for a URLencoded path name for every R library path in use, when in fact those URL encoded path names may be over 8000 characters long for a 4096 character path.

This seems limiting even on a desktop, where something like /usr/lib/R would normally fit easily, but it is way too small for large datacenter installations where nodes running R may be scheduled in different VMs with long directory names.

Most long file name issues were addressed with R ~2.10 in the C code, but this one has come up also at my employer.

To reproduce, try something like :

long.dir<- paste("/home", Sys.getenv("USER"), paste(rep("a", 2000), collapse="/"), sep="/")
system(paste("mkdir -p", long.dir))
Sys.setenv("R_LIBS_USER"=long.dir)
installed.packages(long.dir)

This should work regardless of how long the directory names from .libPaths() are.  A different cache filename should be created.  Instead of URLencode a more succinct hash could be used, for example.
Comment 1 Murray Stokely 2011-09-07 19:00:10 UTC
Created attachment 1226 [details]
Patch to utils/R/packages.R to support longer libPaths in installed.packages()

Patch against r56973 / r-devel as of 7 Sept 2011
Comment 2 Brian Ripley 2011-09-22 18:35:36 UTC
changed in trunk.
Comment 3 Brian Ripley 2011-09-26 07:36:20 UTC
But not that the patch supplied did not work on Windows, and the
implemented solution is to hash file names.