Skip to content

Commit

Permalink
windows: Fix open fd error on windows
Browse files Browse the repository at this point in the history
Unlike linux, windows will not allow a rename to
happen if there is an open fd. Hence, closing the
fd's before renaming

Signed-off-by: Mohammed Rafi KC <[email protected]>
  • Loading branch information
rafikc30 authored and portante committed May 17, 2023
1 parent 47c747e commit aa2519d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sync_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ def write_sync_file(fpath, contents):
sgf.write(contents)
sgf.flush()
os.fsync(sgf.fileno()) # file should close when you exit block
os.rename(fpath + notyet, fpath)
os.rename(fpath + notyet, fpath)


def write_pickle(fpath, obj):
with open(fpath + notyet, "wb") as result_file:
pickle.dump(obj, result_file)
result_file.flush()
os.fsync(result_file.fileno()) # or else reader may not see data
os.rename(fpath + notyet, fpath)
os.rename(fpath + notyet, fpath)


# create directory if it's not already there
Expand Down

0 comments on commit aa2519d

Please sign in to comment.