File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -34,8 +34,26 @@ fetch_and_run_tmux_resurrect_save_script() {
3434 fi
3535}
3636
37+ acquire_lock () {
38+ # Sometimes tmux starts multiple saves in parallel. We want only one
39+ # save to be running, otherwise we can get corrupted saved state.
40+ local lockdir_prefix=" /tmp/tmux-continuum-$( current_tmux_server_pid) -lock-"
41+ # The following implements a lock that auto-expires after 100...200s.
42+ local lock_generation=$(( `date +% s` / 100 ))
43+ local lockdir1=" ${lockdir_prefix}${lock_generation} "
44+ local lockdir2=" ${lockdir_prefix} $(( $lock_generation + 1 )) "
45+ if mkdir " $lockdir1 " ; then
46+ trap " rmdir " $lockdir1 " " EXIT
47+ if mkdir " $lockdir2 " ; then
48+ trap " rmdir " $lockdir1 " " $lockdir2 " " EXIT
49+ return 0
50+ fi
51+ fi
52+ return 1 # Someone else has the lock.
53+ }
54+
3755main () {
38- if supported_tmux_version_ok && auto_save_not_disabled && enough_time_since_last_run_passed; then
56+ if supported_tmux_version_ok && auto_save_not_disabled && enough_time_since_last_run_passed && acquire_lock ; then
3957 fetch_and_run_tmux_resurrect_save_script
4058 fi
4159}
You can’t perform that action at this time.
0 commit comments