Skip to content

Commit

Permalink
Add deduplicate conflict mode to only skip actual duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
Mia A authored and Mia A committed Aug 4, 2024
1 parent f227f6b commit e9cbc90
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion organize/actions/common/conflict.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from pathlib import Path
from typing import TYPE_CHECKING, Literal, NamedTuple
import filecmp

from organize.output import Output
from organize.resource import Resource
Expand All @@ -11,7 +12,7 @@
from jinja2 import Template

# TODO: keep_newer, keep_older, keep_bigger, keep_smaller
ConflictMode = Literal["skip", "overwrite", "trash", "rename_new", "rename_existing"]
ConflictMode = Literal["skip", "overwrite", "deduplicate", "trash", "rename_new", "rename_existing"]


class ConflictResult(NamedTuple):
Expand Down Expand Up @@ -103,6 +104,17 @@ def _print(msg: str):

delete(path=dst)
return ConflictResult(skip_action=False, use_dst=dst)

elif conflict_mode == "deduplicate":
if filecmp.cmp(res.path, dst, shallow=True):
_print(f"Duplicate skipped.")
return ConflictResult(skip_action=True, use_dst=res.path)
else:
new_path = next_free_name(
dst=dst,
template=rename_template,
)
return ConflictResult(skip_action=False, use_dst=new_path)

elif conflict_mode == "rename_new":
new_path = next_free_name(
Expand Down

0 comments on commit e9cbc90

Please sign in to comment.