Skip to content

Commit

Permalink
also converting Windows paths in older generations
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrpfn committed Nov 25, 2024
1 parent 01a7e7d commit 8cf3908
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ascmhl/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def create_for_folder_subcommand(

# we collect all paths we expect to find first and remove every path that we actually found while
# traversing the file system, so this set will at the end contain the file paths not found in the file system
not_found_paths = existing_history.set_of_file_paths()
not_found_paths = existing_history.set_of_file_paths(potential_windows_paths=convert_windows_paths)
renamed_files = existing_history.renamed_path_with_previous_path()
not_found_paths = {p if renamed_files.get(p, None) is None else renamed_files[p] for p in not_found_paths}
new_paths = set()
Expand Down
8 changes: 6 additions & 2 deletions ascmhl/hashlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from typing import List, Dict, Optional, Set
from datetime import datetime
import os
from pathlib import Path

from . import logger
from .ignore import MHLIgnoreSpec
Expand Down Expand Up @@ -76,10 +77,13 @@ def find_or_create_media_hash_for_path(self, relative_path, file_size, file_modi
self.append_hash(media_hash)
return media_hash

def set_of_file_paths(self, root_path) -> Set[str]:
def set_of_file_paths(self, root_path, potential_windows_paths=False) -> Set[str]:
all_paths = set()
for media_hash in self.media_hashes:
all_paths.add(os.path.join(root_path, media_hash.path))
media_path = media_hash.path
if potential_windows_paths:
media_path = Path(media_path).as_posix()
all_paths.add(os.path.join(root_path, media_path))
return all_paths

def renamed_path_with_previous_path(self, root_path):
Expand Down
6 changes: 4 additions & 2 deletions ascmhl/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,12 @@ def find_history_for_path(self, relative_path: str) -> Tuple[MHLHistory, str]:
dir_path = os.path.dirname(dir_path)
return self, relative_path

def set_of_file_paths(self) -> Set[str]:
def set_of_file_paths(self, potential_windows_paths=False) -> Set[str]:
all_paths = set()
for hash_list in self.hash_lists:
all_paths.update(hash_list.set_of_file_paths(self.get_root_path()))
all_paths.update(
hash_list.set_of_file_paths(self.get_root_path(), potential_windows_paths=potential_windows_paths)
)
for child_history in self.child_histories:
all_paths.update(child_history.set_of_file_paths())
return all_paths
Expand Down

0 comments on commit 8cf3908

Please sign in to comment.