Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hd1801/e7d9b5153ee9eac7e5769ccdec2980f5 to your computer and use it in GitHub Desktop.
Save hd1801/e7d9b5153ee9eac7e5769ccdec2980f5 to your computer and use it in GitHub Desktop.
Atomic Directory Commits #linux #cli

Atomic Directory Commits

Sometimes you need to "commit" a directory to target location atomically. That is you don't want to have a partial directory where only a subset of files is stored.

Being able to atomically commit a directory relies on 2 conditions:

  1. Having an atomic rename operation where the source and target is on the same filesystem device.
  2. Being able to create a temporary directory descriptor similar to a temporary file descriptor.

Condition 2 can be relaxed if you can accept that garbage temporary files may be left on the filesystem device.

An external system would have to be used to clean up the garbage. Cleaning up garbage directories is not atomic.

You have to delete each individual file recursive within the garbage directory.

One way to achieve condition 1 for many programs is to set the TMPDIR environment variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment