Refactor move_preview_frames function

Refactor move_preview_frames to simplify logic and improve error handling.
This commit is contained in:
Sean Kelly 2026-05-20 09:30:02 -07:00 committed by GitHub
parent 8ea46e7c6c
commit da0eab194f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -342,20 +342,30 @@ def move_preview_frames(loc: str) -> None:
preview_holdover = os.path.join(CLIPS_DIR, "preview_restart_cache") preview_holdover = os.path.join(CLIPS_DIR, "preview_restart_cache")
preview_cache = os.path.join(CACHE_DIR, "preview_frames") preview_cache = os.path.join(CACHE_DIR, "preview_frames")
try:
if loc == "clips": if loc == "clips":
shutil.move(preview_cache, preview_holdover) src = preview_cache
dst = preview_holdover
elif loc == "cache": elif loc == "cache":
if not os.path.exists(preview_holdover): src = preview_holdover
dst = preview_cache
else:
return return
if not os.access(preview_holdover, os.R_OK | os.W_OK): try:
if not os.path.exists(src):
return
shutil.move(src, dst)
except PermissionError:
logger.error( logger.error(
"Insufficient permissions on preview restart cache at %s", "Insufficient permissions while moving preview restart cache from %s to %s",
preview_holdover, src,
dst,
) )
return
shutil.move(preview_holdover, preview_cache)
except shutil.Error: except shutil.Error:
logger.error("Failed to restore preview cache.") logger.error(
"Failed to move preview restart cache from %s to %s",
src,
dst,
)