mirror of https://github.com/zulip/zulip.git
python: Convert os.open(…, O_EXCL) to open(…, "x").
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
358f1f9ba7
commit
3a8cf869db
|
@ -85,13 +85,10 @@ def get_or_create_key_prefix() -> str:
|
|||
|
||||
filename = os.path.join(settings.DEPLOY_ROOT, "var", "remote_cache_prefix")
|
||||
try:
|
||||
fd = os.open(filename, os.O_CREAT | os.O_EXCL | os.O_RDWR, 0o444)
|
||||
prefix = secrets.token_hex(16) + ':'
|
||||
# This does close the underlying file
|
||||
with os.fdopen(fd, 'w') as f:
|
||||
with open(filename, 'x') as f:
|
||||
prefix = secrets.token_hex(16) + ':'
|
||||
f.write(prefix + "\n")
|
||||
except OSError:
|
||||
# The file already exists
|
||||
except FileExistsError:
|
||||
tries = 1
|
||||
while tries < 10:
|
||||
with open(filename) as f:
|
||||
|
|
|
@ -173,7 +173,8 @@ class Command(ZulipBaseCommand):
|
|||
|
||||
tarball_path = output_dir.rstrip("/") + ".tar.gz"
|
||||
try:
|
||||
os.close(os.open(tarball_path, os.O_CREAT | os.O_EXCL | os.O_WRONLY, 0o666))
|
||||
with open(tarball_path, "x"):
|
||||
pass
|
||||
except FileExistsError:
|
||||
raise CommandError(f"Refusing to overwrite existing tarball: {tarball_path}. Aborting...")
|
||||
|
||||
|
|
Loading…
Reference in New Issue