mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 16:37:23 +00:00
export_usermessage_batch: Use os.rename.
This avoids an extra stat call to check whether the target is a directory. Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
83eca256a4
commit
234f7245cf
@@ -1,7 +1,6 @@
|
|||||||
import glob
|
import glob
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import shutil
|
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
@@ -29,8 +28,8 @@ class Command(BaseCommand):
|
|||||||
locked_path = partial_path.replace(".json.partial", ".json.locked")
|
locked_path = partial_path.replace(".json.partial", ".json.locked")
|
||||||
output_path = partial_path.replace(".json.partial", ".json")
|
output_path = partial_path.replace(".json.partial", ".json")
|
||||||
try:
|
try:
|
||||||
shutil.move(partial_path, locked_path)
|
os.rename(partial_path, locked_path)
|
||||||
except Exception:
|
except FileNotFoundError:
|
||||||
# Already claimed by another process
|
# Already claimed by another process
|
||||||
continue
|
continue
|
||||||
logging.info("Thread %s processing %s", options['thread'], output_path)
|
logging.info("Thread %s processing %s", options['thread'], output_path)
|
||||||
@@ -38,5 +37,5 @@ class Command(BaseCommand):
|
|||||||
export_usermessages_batch(locked_path, output_path, options["consent_message_id"])
|
export_usermessages_batch(locked_path, output_path, options["consent_message_id"])
|
||||||
except Exception:
|
except Exception:
|
||||||
# Put the item back in the free pool when we fail
|
# Put the item back in the free pool when we fail
|
||||||
shutil.move(locked_path, partial_path)
|
os.rename(locked_path, partial_path)
|
||||||
raise
|
raise
|
||||||
|
|||||||
Reference in New Issue
Block a user