Skip to content

Instantly share code, notes, and snippets.

@kgoess
Created January 8, 2016 05:19
Show Gist options
  • Save kgoess/9900d31cc32fe1412f5f to your computer and use it in GitHub Desktop.
Save kgoess/9900d31cc32fe1412f5f to your computer and use it in GitHub Desktop.
# the "current" link is what the app should use
# "upcoming current" is where the updated files get written to
#
# start off with it pointing to tempdir1
reigate:xx kevin$ lsl
total 16
drwxr-xr-x 2 kevin staff 68 Jan 7 21:07 tempdir2/
drwxr-xr-x 2 kevin staff 68 Jan 7 21:11 tempdir1/
lrwxr-xr-x 1 kevin staff 8 Jan 7 21:12 current@ -> tempdir1
lrwxr-xr-x 1 kevin staff 8 Jan 7 21:12 upcoming_current@ -> tempdir2
# use rename for an atomic rename, see "man 2 rename":
# 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.
# (perl is just an easy way for me to access it)
reigate:xx kevin$ perl -le 'rename "upcoming_current", "current" or die $!'
reigate:xx kevin$ lsl
total 8
drwxr-xr-x 2 kevin staff 68 Jan 7 21:07 tempdir2/
drwxr-xr-x 2 kevin staff 68 Jan 7 21:11 tempdir1/
lrwxr-xr-x 1 kevin staff 8 Jan 7 21:12 current@ -> tempdir2
# now the app accessing "current" gets the new stuff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment