[Rd] unlink fails to remove symbolic links

Prof Brian Ripley ripley at stats.ox.ac.uk
Sat Mar 21 18:03:12 CET 2009


On Sat, 21 Mar 2009, Martin Morgan wrote:

> A little more precisely, unlink fails when the file being unlinked is
> a broken symbolic link (as in the example below). This is because
> R_FileExists checks stat() == 0, and stat fails (returns -1) when
> trying to resolve the broken link. Perhaps lstat() is more
> appropriate?

lstat is not portable, and I don't think it is appropriate for most
uses of R_FileExists.

I don't think there is anything new about this, and it does seem only 
to apply to broken links.  At a quick look the best solution looks to 
be to remove the pretest, but I need to check in more detail.


>
> Martin
>
> Martin Morgan <mtmorgan at fhcrc.org> writes:
>
>> unlink fails to remove symbolic links. This is more prominent now --
>> when a package creates symbolic links during installation, 00LOCK is
>> not removed.
>>
>> Martin
>>
>>> setwd(tempdir())
>>> fl <- tempfile(); file.create(fl)
>> [1] TRUE
>>> lnFile <- tempfile(); system(paste("ln -s", fl, lnFile))
>>> list.files()
>> [1] "file19495cff" "file74b0dc51"
>>> unlink(fl); unlink(lnFile)
>>> list.files()
>> [1] "file19495cff"
>>> lnFile
>> [1] "/tmp/Rtmpb0kd7B/file19495cff"
>>
>>> sessionInfo()
>> R version 2.10.0 Under development (unstable) (2009-03-21 r48173)
>> x86_64-unknown-linux-gnu
>>
>> locale:
>> LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-\
>> 8;LC_IDENTIFICATION=C
>>
>> attached base packages:
>> [1] stats     graphics  grDevices utils     datasets  methods   base
>>
>> loaded via a namespace (and not attached):
>> [1] tools_2.10.0
>
> -- 
> Martin Morgan
> Computational Biology / Fred Hutchinson Cancer Research Center
> 1100 Fairview Ave. N.
> PO Box 19024 Seattle, WA 98109
>
> Location: Arnold Building M2 B169
> Phone: (206) 667-2793
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list