Skip to content
Prev 42356 / 63424 Next

misfeature: forced file.copy() of a file over itself truncates the file ...

Since the problem can only occur if the 'to' file
exists, a check like
   if (normalizePath(from) == normalizePath(to)) {
      stop("'from' and 'to' files are the same")
   }
(after verifying that 'to', and 'from', exist)
would avoid the problem.

S+ has a function, match.path, that can say if two paths refer to
the same file (on Unixen compare inode and device
numbers, on Windows compare the output of normalizePath),
That avoids automounter/NFS problems like the following.

We have a unix machine has two names, "sea-union" and "seabldlnx3201",
and the /nfs directory contains both names.  At the shell (on a
second Linux machine) we can see they refer to the same place:
   % pwd
   /nfs/sea-union
   % ls -id usr /nfs/seabldlnx3201/usr /nfs/sea-union/usr
   358337 /nfs/seabldlnx3201/usr/  358337 /nfs/sea-union/usr/  358337 usr/
   % df usr /nfs/seabldlnx3201/usr /nfs/sea-union/usr
   Filesystem           1K-blocks      Used Available Use% Mounted on
   sea-union:/usr        15385888   3526656  11077664  25% /nfs/sea-union/usr
   seabldlnx3201:/usr    15385888   3526656  11077664  25% /nfs/seabldlnx3201/usr
   sea-union:/usr        15385888   3526656  11077664  25% /nfs/sea-union/usr

S+'s match.path also indicates that they are the same   
   S+> getwd()
   [1] "/nfs/sea-union"
   S+> match.path( c("usr", "/nfs/seabldlnx3201/usr"), "/nfs/sea-union/usr")
   [1] 1 1
   (The last indicates that both paths in the first argument match the
   path in the second, as match() does for strings.)
But R's normalizePath() would lead you to think that they are different
directories
   > getwd()
   [1] "/nfs/sea-union"
   > normalizePath(c("usr", "/nfs/seabldlnx3201/usr", "/nfs/sea-union/usr"))
   [1] "/nfs/sea-union/usr"     "/nfs/seabldlnx3201/usr" "/nfs/sea-union/usr"

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com