Skip to content

Instantly share code, notes, and snippets.

@CMCDragonkai
Last active January 8, 2024 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save CMCDragonkai/0be305cd93c9e69491afed76c4862255 to your computer and use it in GitHub Desktop.
Save CMCDragonkai/0be305cd93c9e69491afed76c4862255 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