However, notice that cat doesn't protect you in the same way:

Peters-iMac:tst pd$ echo stuff > A
Peters-iMac:tst pd$ ln -s A B
Peters-iMac:tst pd$ ls -l
total 8
-rw-r--r--  1 pd  staff  6 Sep 13 15:20 A
lrwxr-xr-x  1 pd  staff  1 Sep 13 15:20 B -> A
Peters-iMac:tst pd$ cp A B
cp: B and A are identical (not copied).
Peters-iMac:tst pd$ ls -l
total 8
-rw-r--r--  1 pd  staff  6 Sep 13 15:20 A
lrwxr-xr-x  1 pd  staff  1 Sep 13 15:20 B -> A
Peters-iMac:tst pd$ cat A > B
Peters-iMac:tst pd$ ls -l
total 0
-rw-r--r--  1 pd  staff  0 Sep 13 15:20 A
lrwxr-xr-x  1 pd  staff  1 Sep 13 15:20 B -> A

(& I suspect that cp did likewise in early Unices). Bug or not, it would be 
good if we could detect when "from" and "to" refer to the same file, but I'm 
not sure how to do that.

-pd

> On 13 Sep 2019, at 11:56 , Marc Girondot via R-help <r-help@r-project.org> 
> wrote:
> 
> 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).
> 
> ______________________________________________
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd....@cbs.dk  Priv: pda...@gmail.com

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to