From 34e11a6770519cfabcd3af25d931bfc11b63ffce Mon Sep 17 00:00:00 2001 From: vg Date: Tue, 12 Jan 2021 11:23:37 +0100 Subject: add file locking for simplest cases protection --- scripts/xattr_user_id | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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()) -- cgit v1.2.3