[Rd] file.symlink() creates zero-size file/link on Windows 7/NTFS/admin

From: Henrik Bengtsson <hb_at_biostat.ucsf.edu>
Date: Wed, 31 Oct 2012 14:04:04 -0700


With R 2.15.2 patched (2012-10-29 r61044) and R devel (2012-10-29r61044) on **Windows 7 w/ NTFS ** running in admin mode, I get:

EXAMPLE:
> cat("Hello world", file="foo.txt")
> file.exists("foo-lnk.txt")
[1] FALSE
> res <- file.symlink(from="foo.txt", to="foo-lnk.txt")
> warnings()

NULL
> res

[1] TRUE
> file.info("foo-lnk.txt")$size

[1] 0

That zero-size "foo-lnk.txt" file/link is invalid, correct? Am I doing something wrong? Should I expect file.syslink() to work on my system?

SUGGESTION:
Currently I have a wrapper that checks if file.symlink() creates a zero-size file/link, and if so, it file.remove() it. There are several notes/disclaimers in help("file.symlink", package="base") on creating symbolic links on Windows. Despite those, wouldn't it be better if file.symlink() detected that it created an empty file/link and removed it together with a warning/an error analogously to the other conditions it may throw?

DETAILS:
>From src/main/platform.c::do_filesymlink() it looks like it's Windows
that creates the empty file but still returning 0:

#ifdef Win32
[...]
 pCSL = (PCSL) GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "CreateSymbolicLinkW");
 [...]
 LOGICAL(ans)[i] = pCSL(to, from, isDir) != 0;  if(!LOGICAL(ans)[i])
   warning(_("cannot symlink '%ls' to '%ls', reason '%s'"), from, to, formatError(GetLastError()));

> sessionInfo()

R Under development (unstable) (2012-10-29 r61044) Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:

[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached): [1] tools_2.16.0

Thanks,

Henrik



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed 31 Oct 2012 - 21:09:50 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 Wed 31 Oct 2012 - 22:10:50 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