From 40aed6fc5b5ccbfef47194c89a9b58e45c0bddc0 Mon Sep 17 00:00:00 2001 From: tcely Date: Wed, 18 Dec 2024 02:58:33 -0500 Subject: [PATCH] Escape fnmatch special characters in old_stem --- tubesync/sync/models.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tubesync/sync/models.py b/tubesync/sync/models.py index 583ba1c8..9f6365f5 100644 --- a/tubesync/sync/models.py +++ b/tubesync/sync/models.py @@ -751,6 +751,14 @@ class Media(models.Model): STATE_DISABLED_AT_SOURCE: '', STATE_ERROR: '', } + # Path.glob uses fnmatch, so we must escape certain characters + _glob_specials = { + '?': '[?]', + '*': '[*]', + '[': '[[]', + ']': '[]]', # probably not needed, but it won't hurt + } + _glob_translation = str.maketrans(_glob_specials) uuid = models.UUIDField( _('uuid'), @@ -1527,7 +1535,8 @@ class Media(models.Model): stem = Path(stem.stem) old_stem = stem old_prefix_path = old_video_path.parent - other_paths = list(old_prefix_path.glob(str(old_stem) + '*')) + glob_prefix = str(old_stem).translate(_glob_translation) + other_paths = list(old_prefix_path.glob(glob_prefix + '*')) new_video_path.parent.mkdir(parents=True, exist_ok=True) old_video_path.rename(new_video_path)