mirror of
https://github.com/meeb/tubesync.git
synced 2025-06-21 04:26:36 +00:00
Optimize rename_files
This commit is contained in:
parent
1f0169ae4b
commit
c5c340b58f
@ -1514,6 +1514,8 @@ class Media(models.Model):
|
|||||||
old_file_str = other_path.name
|
old_file_str = other_path.name
|
||||||
new_file_str = new_stem + old_file_str[len(old_stem):]
|
new_file_str = new_stem + old_file_str[len(old_stem):]
|
||||||
new_file_path = Path(new_prefix_path / new_file_str)
|
new_file_path = Path(new_prefix_path / new_file_str)
|
||||||
|
if new_file_path == other_path:
|
||||||
|
continue
|
||||||
log.debug(f'Considering replace for: {self!s}\n\t{other_path!s}\n\t{new_file_path!s}')
|
log.debug(f'Considering replace for: {self!s}\n\t{other_path!s}\n\t{new_file_path!s}')
|
||||||
# it should exist, but check anyway
|
# it should exist, but check anyway
|
||||||
if other_path.exists():
|
if other_path.exists():
|
||||||
@ -1525,6 +1527,8 @@ class Media(models.Model):
|
|||||||
old_file_str = fuzzy_path.name
|
old_file_str = fuzzy_path.name
|
||||||
new_file_str = new_stem + old_file_str[len(fuzzy_stem):]
|
new_file_str = new_stem + old_file_str[len(fuzzy_stem):]
|
||||||
new_file_path = Path(new_prefix_path / new_file_str)
|
new_file_path = Path(new_prefix_path / new_file_str)
|
||||||
|
if new_file_path == fuzzy_path:
|
||||||
|
continue
|
||||||
log.debug(f'Considering rename for: {self!s}\n\t{fuzzy_path!s}\n\t{new_file_path!s}')
|
log.debug(f'Considering rename for: {self!s}\n\t{fuzzy_path!s}\n\t{new_file_path!s}')
|
||||||
# it quite possibly was renamed already
|
# it quite possibly was renamed already
|
||||||
if fuzzy_path.exists() and not new_file_path.exists():
|
if fuzzy_path.exists() and not new_file_path.exists():
|
||||||
@ -1538,8 +1542,9 @@ class Media(models.Model):
|
|||||||
|
|
||||||
# try to remove empty dirs
|
# try to remove empty dirs
|
||||||
parent_dir = old_video_path.parent
|
parent_dir = old_video_path.parent
|
||||||
|
stop_dir = self.source.directory_path
|
||||||
try:
|
try:
|
||||||
while parent_dir.is_dir():
|
while parent_dir.is_relative_to(stop_dir):
|
||||||
parent_dir.rmdir()
|
parent_dir.rmdir()
|
||||||
log.info(f'Removed empty directory: {parent_dir!s}')
|
log.info(f'Removed empty directory: {parent_dir!s}')
|
||||||
parent_dir = parent_dir.parent
|
parent_dir = parent_dir.parent
|
||||||
|
Loading…
Reference in New Issue
Block a user