mirror of https://github.com/openXC7/prjxray.git
utils: add file locking
Signed-off-by: Alessandro Comodi <acomodi@antmicro.com>
This commit is contained in:
parent
b00c8332e3
commit
5e5217c631
|
|
@ -536,8 +536,10 @@ def update_seg_fns(
|
||||||
changes += new_changes
|
changes += new_changes
|
||||||
|
|
||||||
with open(fn_out, "w") as f:
|
with open(fn_out, "w") as f:
|
||||||
|
util.lock_file(f, 10)
|
||||||
for line in sorted(lines):
|
for line in sorted(lines):
|
||||||
print(line, file=f)
|
print(line, file=f)
|
||||||
|
util.unlock_file(f)
|
||||||
|
|
||||||
if changes is not None:
|
if changes is not None:
|
||||||
seg_files += 1
|
seg_files += 1
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,7 @@ import sys
|
||||||
import json
|
import json
|
||||||
import utils.xjson as xjson
|
import utils.xjson as xjson
|
||||||
import utils.cmp as cmp
|
import utils.cmp as cmp
|
||||||
|
from prjxray.util import lock_file, unlock_file
|
||||||
|
|
||||||
|
|
||||||
def split_all(s, chars):
|
def split_all(s, chars):
|
||||||
|
|
@ -344,9 +345,11 @@ def sort_db(pathname):
|
||||||
# copy[i], tosort[i])
|
# copy[i], tosort[i])
|
||||||
|
|
||||||
with open(pathname, 'w') as f:
|
with open(pathname, 'w') as f:
|
||||||
|
lock_file(f, 10)
|
||||||
for _, l in tosort:
|
for _, l in tosort:
|
||||||
f.write(l)
|
f.write(l)
|
||||||
f.write('\n')
|
f.write('\n')
|
||||||
|
unlock_file(f)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
@ -405,8 +408,10 @@ def sort_db_text(n):
|
||||||
rows.sort(key=lambda i: i[0])
|
rows.sort(key=lambda i: i[0])
|
||||||
|
|
||||||
with open(n, 'w') as f:
|
with open(n, 'w') as f:
|
||||||
|
lock_file(f, 10)
|
||||||
for l in rows:
|
for l in rows:
|
||||||
f.write(l[-1])
|
f.write(l[-1])
|
||||||
|
unlock_file(f)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue