Skip to content
Prev 43211 / 63424 Next

file.copy(src, src, recursive=TRUE) causes a segfault (Was: Re: R CMD check . segfault on re-building vignettes)

It appears that file.copy() does not protect against the case when one
copies one directory to a subdirectory of itself resulting in it
trying to create and endless recursive copy of itself.

REPRODUCIBLE EXAMPLE:
src <- "foo"
dir.create(src);
file.copy(src, src, recursive=FALSE) # ok
file.copy(src, src, recursive=TRUE) # PROBLEM
file.exists("foo/foo/foo/foo/foo/foo/foo/foo/") # TRUE
file.exists("foo/foo/foo/foo/foo/foo/foo/foo/foo/foo/foo/") # TRUE

I can reproduce this.

TROUBLESHOOTING:
On R version 2.15.0 (2012-03-30) [Platform: x86_64-pc-linux-gnu (64-bit)] I get
Error: segfault from C stack overflow

but return to a working prompt.  BTW, this follow up causes an R error:
Error: C stack usage is too close to the limit
[1] 2512
List of 1
 $ : chr [1:628] "foo" "foo" "foo" "foo" ...

I guess a possible cause for the segfault is what is hinted at by the
list.files() error; internally there is a write buffer overflow due to
a too long path.

On Windows, i.e. R version 2.15.0 Patched (2012-04-25 r59178)
[Platform: x86_64-pc-mingw32/x64 (64-bit)], I get:
[1] TRUE
Warning message:
In file.copy(src, src, recursive = TRUE) :
  problem creating directory
.\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo\foo:
No such file or directory

Here the maximum file path length of the OS is probably kicking in
before reaching the buffer overflow, cf.
http://aroma-project.org/howtos/UseLongFilenamesOnWindows

My $.02

/Henrik

On Mon, Apr 30, 2012 at 8:48 AM, Sebastian Meyer
<Sebastian.Meyer at ifspm.uzh.ch> wrote: