mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 08:47:12 +03:00
Use atomic file writes for server side cache
We've gotten reports of users receiving corrupt file blobs directly from the server. The corruption doesn't enter the cache pool, and we don't get any further reports of it, so I think it's a transient issue caused certain readers reading the file before the writer has finished writing it. Let's use atomic rename files to make this not happen.
This commit is contained in:
parent
6e7195b8ef
commit
e9a9bad998
@ -199,13 +199,17 @@ def _loadfileblob(repo, cachepath, path, node):
|
||||
dirname = os.path.dirname(filecachepath)
|
||||
if not os.path.exists(dirname):
|
||||
os.makedirs(dirname)
|
||||
f = None
|
||||
try:
|
||||
with open(filecachepath, "w") as f:
|
||||
f.write(text)
|
||||
except IOError:
|
||||
f = util.atomictempfile(filecachepath, "w")
|
||||
f.write(text)
|
||||
except (IOError, OSError):
|
||||
# Don't abort if the user only has permission to read,
|
||||
# and not write.
|
||||
pass
|
||||
finally:
|
||||
if f:
|
||||
f.close()
|
||||
finally:
|
||||
os.umask(oldumask)
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user