Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle non atomic write method when writing on network fs with linux #991

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/rez/serialise.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,18 @@ def open_file_for_write(filepath, mode=None):
with atomic_write(filepath, overwrite=True, **encoding) as f:
f.write(content)

except WindowsError as e:
if attempt == 0:
except OSError as e:
# If we are writing to the network, we can't ensure atomicity
if e.errno == 22:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error no. 22 is an invalid filepath, right? What does that have to do with network paths?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal is to handle the sync method error of atomicwrites:

File "/usr/local/lib/python3.7/site-packages/rez/vendor/atomicwrites/init.py", line 44, in _sync_directory
_proper_fsync(fd)
OSError: [Errno 22] Invalid argument

This is ugly, but atomicwrites doesn't handle properly this error itself

with open(filepath, "w", **encoding) as f:
f.write(content)

elif attempt == 0:
# `overwrite=True` of atomic_write doesn't restore
# writability to the file being written to.
os.chmod(filepath, stat.S_IWRITE | stat.S_IREAD)

else:
elif sys.platform == "win32":
# Under Windows, atomic_write doesn't tell you about
# which file actually failed.
raise WindowsError("%s: '%s'" % (e, filepath))
Expand Down
2 changes: 1 addition & 1 deletion src/rez/utils/_version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


# Update this value to version up Rez. Do not place anything else in this file.
_rez_version = "2.69.6"
_rez_version = "2.69.7"


# Copyright 2013-2016 Allan Johns.
Expand Down