Is moving a file atomic if more than 1 directory is involved?

490 views Asked by At

In NTFS, file moving is atomic as explained here:

[...] if you are running under NTFS then file operations are atomic at the file system level. A rename will occur in a single operation as far as any higher code is concerned.

Does this mean that moving a file is atomic also if it is moved from one directory to another directory? Or only within the same directory?

I'm assuming both directories are located on the same volume.

1

There are 1 answers

3
MJZ On

Yes, they are atomic. Both source and destination directories are locked for the duration of the move, preventing programs from seeing inflight data.

However, this is only "failure atomicity". Your program may do the move, thinking it has moved things (and communicating to another server that it has done so), but the modifications to the control structures themselves hasn't made it to the media. A power loss may discard those changes but NTFS will assure the consistency of the directories (aka, no chkdsk required).

Subsequent program access will either see the files as they are before the move or after the move, but not while-it-is-happening.