aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xscripts/xattr_user_id5
1 files changed, 4 insertions, 1 deletions
diff --git a/scripts/xattr_user_id b/scripts/xattr_user_id
index 28a1d99..7badd9d 100755
--- a/scripts/xattr_user_id
+++ b/scripts/xattr_user_id
@@ -46,9 +46,9 @@ Options:
### standard modules
import contextlib
+import fcntl
import functools
import itertools
-import operator
import os
import sys
@@ -86,6 +86,9 @@ def main():
last_used_id = 0
if args['--state']:
with contextlib.suppress(FileNotFoundError):
+ lock_fd = open(args['--state'], 'r') # locked until program exits
+ # limitation: if file does not exists yet, file won't be locked
+ fcntl.flock(lock_fd, fcntl.LOCK_EX)
with open(args['--state'], encoding='utf8') as stream:
last_used_id = int(stream.read())