Henrik Bengtsson
2012-Oct-31 21:04 UTC
[Rd] file.symlink() creates zero-size file/link on Windows 7/NTFS/admin
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 Windowsthat 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