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

From: Prof Brian Ripley <>
Date: Wed, 02 Mar 2011 07:01:45 +0000 (GMT)

As the help says:

   This is subject to the limitations of the OS's corresponding system    call: ....

E.g. on Fedora 14 'man 2 rename' says, inter alia,

'If newpath already exists it will be atomically replaced (subject to a few conditions; see ERRORS below), so that there is no point at which another process attempting to access newpath will find it missing.

However, when overwriting there will probably be a window in which both oldpath and newpath refer to the file being renamed.

BUGS On NFS file systems, you can not assume that if the operation failed the file was not renamed.'

and for Windows see

where R uses flags (MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED | MOVEFILE_WRITE_THROUGH) Windows 95 was an example of an OS which could delete the 'to' file and fail to move 'from'.

On Tue, 1 Mar 2011, Henrik Bengtsson wrote:

> 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
> ______________________________________________
> mailing list

Brian D. Ripley,        
Professor of Applied Statistics,
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________ mailing list
Received on Wed 02 Mar 2011 - 07:06:03 GMT

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 Thu 03 Mar 2011 - 08:20:25 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive