From hb at biostat.ucsf.edu  Wed Mar  2 05:41:53 2011
From: hb at biostat.ucsf.edu (Henrik Bengtsson)
Date: Tue, 1 Mar 2011 20:41:53 -0800
Subject: [Rd] file.rename(): Guaranteed to be complete or not at all?
Message-ID: <AANLkTimqGAiRiWdv8j1UjyXOZmSP-OhyLD_fWGu50N+R@mail.gmail.com>

Hi,

assume I have an existing file 'pathname' and I want to rename it to
'pathnameN' (which does not exist).  I use:

res <- file.rename(pathname, pathnameN);

Is it guaranteed that:

(1) if res == TRUE, the file now have name 'pathnameN' and there is no
file with name 'pathname'?
(2) if res == FALSE, nothing has changed?

or could it theoretically also be the case that

(3) there are say two identical files named 'pathname' and 'pathnameN',
(4) or worse, that neither exists?

I can see how (3) could happen if the file is renamed by first using
file.copy() and then file.remove() while there is lack of write/delete
permission for the latter.

Currently, my code asserts that (3) and (4) did not happen.  Is that
unnecessary - does file.rename() do that for me (regardless of OS)?

Thanks

Henrik



[Rd] file.rename(): Guaranteed to be complete or not at all?
Henrik Bengtsson