[R] Bug (?): file.copy() erases 'from' file if the "to" file already exists and is a symlinked file

Marc Girondot m@rc_grt @end|ng |rom y@hoo@|r
Fri Sep 13 11:56:55 CEST 2019


If file.copy() is used to replace a symlinked file, it erases the 
original file and does not copy the file. The original file is lost.

 > version
 ???????????????????????????? _
platform???????????? x86_64-apple-darwin15.6.0
arch???????????????????? x86_64
os???????????????????????? darwin15.6.0
system???????????????? x86_64, darwin15.6.0
status???????????????? Patched
major?????????????????? 3
minor?????????????????? 6.1
year???????????????????? 2019
month?????????????????? 09
day?????????????????????? 06
svn rev?????????????? 77160
language???????????? R
version.string R version 3.6.1 Patched (2019-09-06 r77160)
nickname???????????? Action of the Toes

#########################

Here is a reproducible example:

A <- 10
save(A, file="A.Rdata")
file.symlink(from="A.Rdata", to="B.Rdata")
rm(A)

load(file="B.Rdata")
print(A)?????????????????????? # Perfect

system("ls -l")
## -rw-r--r--?? 1 marcgirondot?? staff?????????? 70 13 sep 11:44 A.Rdata
## lrwxr-xr-x?? 1 marcgirondot?? staff???????????? 7 13 sep 11:44 B.Rdata -> A.Rdata

file.copy(from="A.Rdata", to="B.Rdata", overwrite = TRUE)

system("ls -l")
## -rw-r--r--?? 1 marcgirondot?? staff???????????? 0 13 sep 11:44 A.Rdata
## lrwxr-xr-x?? 1 marcgirondot?? staff???????????? 7 13 sep 11:44 B.Rdata -> A.Rdata

###############

A.Rdata becomes empty: 0B
The content of A.Rdata is lost

################
In terminal the problem does not occur
################

marcgirondot$ ls
A.Rdata
marcgirondot$ ln -s A.Rdata B.Rdata
marcgirondot$ ls -l
-rw-r--r--?? 1 marcgirondot?? staff?????????? 70 13 sep 11:38 A.Rdata
lrwxr-xr-x?? 1 marcgirondot?? staff???????????? 7 13 sep 11:38 B.Rdata -> A.Rdata
marcgirondot$ cp A.Rdata B.Rdata
cp: B.Rdata and A.Rdata are identical (not copied).



More information about the R-help mailing list