don't overwrite segments that already exist (#3995)

This commit is contained in:
Blake Blackshear 2022-10-01 18:11:29 -05:00 committed by GitHub
parent 10783fec49
commit 8669c29e3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -276,13 +276,13 @@ class RecordingMaintainer(threading.Thread):
file_path = os.path.join(directory, file_name)
try:
if not os.path.exists(file_path):
start_frame = datetime.datetime.now().timestamp()
# copy then delete is required when recordings are stored on some network drives
shutil.copyfile(cache_path, file_path)
logger.debug(
f"Copied {file_path} in {datetime.datetime.now().timestamp()-start_frame} seconds."
)
os.remove(cache_path)
rand_id = "".join(
random.choices(string.ascii_lowercase + string.digits, k=6)
@ -298,6 +298,9 @@ class RecordingMaintainer(threading.Thread):
# TODO: update this to store list of active objects at some point
objects=active_count,
)
else:
logger.warning(f"Ignoring segment because {file_path} already exists.")
os.remove(cache_path)
except Exception as e:
logger.error(f"Unable to store recording segment {cache_path}")
Path(cache_path).unlink(missing_ok=True)