Re: [Rd] misfeature: forced file.copy() of a file over itself truncates the file ...

From: Ben Bolker <bbolker_at_gmail.com>
Date: Tue, 31 Jan 2012 19:16:09 +0000

Ben Bolker <bbolker <at> gmail.com> writes:

>

  Bump. Will I be scolded if I submit this as a bug report/wishlist item?

  Test case:

> fn <- "tmp.dat"
> x <- 1:3
> dump("x",file=fn)
> file.info(fn) ## 9 bytes
> file.copy(paste("./",fn,sep=""),fn,overwrite=TRUE)
> file.info(fn) ## 0 bytes (!!)
>
> Normally file.copy() checks and disallows overwriting a file with
> itself, but it only checks whether character string 'from' is the same
> as character string 'to' and not whether the copy refers to the same
> file by different names, so it lets this go ahead. It then creates a
> new file with the name of 'to' using file.create():
>
> ‘file.create’ creates files with the given names if they do not
> already exist and truncates them if they do.
>
> This trashes the existing 'from' file (which was not detected).
> file.copy() then happily appends the contents of 'from' (which is now
> empty) to 'to' ...
>
  

 [snip]

  My proposed fix (thanks to W. Dunlap) is to use normalizePath(); as he points out, this won't catch situations where the same file can be referred to via an NFS mount, but it should help at least. Writing a platform-independent version a la S-PLUS's match.path() seemed to much work at the moment.


  thanks
    Ben Bolker



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue 31 Jan 2012 - 19:21:53 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 31 Jan 2012 - 20:20:13 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive