Skip to content

Commit

Permalink
fix: check for duplicated entries
Browse files Browse the repository at this point in the history
  • Loading branch information
F33RNI committed Jan 5, 2024
1 parent e8cccfc commit 1f1b4dc
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions Backupper.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,20 @@ def parse_input_entries(self) -> Dict:
# Extract current skip flag
skip_current = input_entry["skip"]

# Prevent non-skipped duplicates
if input_path in input_entries:
# Extract previous skip flag
skip_previous = input_entries[input_path]
# Convert to relative path (as it will be in backup dir)
input_path_rel = os.path.relpath(input_path, os.path.dirname(input_path))

# If previous one was not skipped and new one also now -> raise an error
if not skip_previous and not skip_current:
raise Exception(f"Duplicated path: {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))

# Check if it's the same path
if os.path.normpath(existing_path_rel) == os.path.normpath(input_path_rel):
# If existing one was not skipped and new one also now -> raise an error
if not existing_path_skip and not skip_current:
raise Exception(f"Duplicated path: {input_path}")

# Check if it exists
if not skip_current and not os.path.exists(input_path):
Expand Down

0 comments on commit 1f1b4dc

Please sign in to comment.