utils: add file locking
Signed-off-by: Alessandro Comodi <acomodi@antmicro.com>
diff --git a/utils/dbfixup.py b/utils/dbfixup.py
index a08bf5a..0e3310d 100755
--- a/utils/dbfixup.py
+++ b/utils/dbfixup.py
@@ -536,8 +536,10 @@
changes += new_changes
with open(fn_out, "w") as f:
+ util.lock_file(f, 10)
for line in sorted(lines):
print(line, file=f)
+ util.unlock_file(f)
if changes is not None:
seg_files += 1
diff --git a/utils/sort_db.py b/utils/sort_db.py
index 7256b45..2d09a86 100755
--- a/utils/sort_db.py
+++ b/utils/sort_db.py
@@ -65,6 +65,7 @@
import json
import utils.xjson as xjson
import utils.cmp as cmp
+from prjxray.util import lock_file, unlock_file
def split_all(s, chars):
@@ -344,9 +345,11 @@
# copy[i], tosort[i])
with open(pathname, 'w') as f:
+ lock_file(f, 10)
for _, l in tosort:
f.write(l)
f.write('\n')
+ unlock_file(f)
return True
@@ -405,8 +408,10 @@
rows.sort(key=lambda i: i[0])
with open(n, 'w') as f:
+ lock_file(f, 10)
for l in rows:
f.write(l[-1])
+ unlock_file(f)
return True