is os.Rename an atomic system level operation?

910 views
Skip to first unread message

Isaac Mosquera

unread,
Oct 7, 2013, 7:41:26 PM10/7/13
to golan...@googlegroups.com
is os.Rename an atomic system level operation?

Rob Pike

unread,
Oct 7, 2013, 7:50:14 PM10/7/13
to Isaac Mosquera, golan...@googlegroups.com
No.

-rob

Isaac Mosquera

unread,
Oct 7, 2013, 8:59:00 PM10/7/13
to golan...@googlegroups.com
If not rename, what is the recommended approach for an atomic move?

Matt Harden

unread,
Oct 7, 2013, 9:07:38 PM10/7/13
to golan...@googlegroups.com
On Linux it is, though only for local filesystems. See http://man7.org/linux/man-pages/man2/rename.2.html.

John Nagle

unread,
Oct 7, 2013, 11:17:57 PM10/7/13
to golan...@googlegroups.com
On Windows Vista and later, Win32 ReplaceFile.

http://msdn.microsoft.com/en-us/library/windows/desktop/aa365512%28v=vs.85%29.aspx

This is atomic for moves within an NTFS file system, which have
an internal transaction journal, but not for FAT file systems or
networked file systems.

For a general discussion of file operation atomicity on Windows see

http://msdn.microsoft.com/en-us/library/windows/desktop/hh802690%28v=vs.85%29.aspx#applications_updating_a_single_file_with_document-like_data

John Nagle



Thomas Bushnell, BSG

unread,
Oct 8, 2013, 11:16:24 AM10/8/13
to Rob Pike, Isaac Mosquera, golan...@googlegroups.com
Huh? On Posix systems, at least, it's syscall.Rename, which is required by Posix to be atomic.

I can't speak to other systems at all.


On Mon, Oct 7, 2013 at 4:50 PM, Rob Pike <r...@golang.org> wrote:
No.

-rob

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Rob Pike

unread,
Oct 8, 2013, 11:32:36 AM10/8/13
to Thomas Bushnell, BSG, Isaac Mosquera, golan...@googlegroups.com
There are systems where it cannot be done atomically, therefore it is not atomic.

-rob

Reply all
Reply to author
Forward
0 new messages