Skip to content

Commit

Permalink
feat: proper entries skip
Browse files Browse the repository at this point in the history
  • Loading branch information
F33RNI committed Jan 24, 2024
1 parent d72d4a6 commit 019dcdf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Backupper.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ def parse_input_entries(self) -> Dict:
input_path_rel = os.path.relpath(input_path, os.path.dirname(input_path))

# Prevent non-skipped duplicates
# TODO: Optimize this code
for existing_path, existing_path_skip in input_entries.items():
# Convert to relative path
existing_path_rel = os.path.relpath(existing_path, os.path.dirname(existing_path))
Expand Down Expand Up @@ -522,6 +521,8 @@ def _generate_tree(
"""
logging.info(f"Generating tree for {len(entries)} entries")

# TODO: remain "skip" only in parent entries

# Create recursion queue and add each root dir
directories_to_parse_queue = multiprocessing.Queue(-1)
for path_abs, skip in entries.items():
Expand Down
12 changes: 11 additions & 1 deletion delete_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,19 @@ def delete_files(
delete_flag = True
if filepath_rel in input_tree[tree_type]:
skip_ = input_tree[tree_type][filepath_rel]["skip"]
if not (delete_skipped and skip_):
if not skip_ or (skip_ and not delete_skipped):
delete_flag = False

# Can not find file directly in input_tree -> try to find it's parent dir
else:
path_components = os.path.normpath(filepath_rel).split(os.path.sep)
if len(path_components) > 1:
filepath_rel_root_dir = path_components[0].strip()
if filepath_rel_root_dir in input_tree["dirs"]:
skip_ = input_tree["dirs"][filepath_rel_root_dir]["skip"]
if not skip_ or (skip_ and not delete_skipped):
delete_flag = False

# Skip if we don't need to delete it
if not delete_flag:
continue
Expand Down
4 changes: 4 additions & 0 deletions tree_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ def tree_parser(
logging.info(f"No more directories to parse! tree_parser() with PID {current_pid} exited")
return

# Ignore skipped entries
if skip:
continue

# Convert parent dir to absolute path
parent_dir_abs = os.path.join(root_dir, parent_dir)

Expand Down

0 comments on commit 019dcdf

Please sign in to comment.