Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions library/symlink_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,17 @@ def compare_permissions(src: Path, dest: Path) -> bool:
src_path = root / name if name != root else root
dst_path = dest / src_path.relative_to(src)

if not dst_path.exists(): # `src_path` guaranteed to exist
continue

if src_path.is_symlink() or dst_path.is_symlink():
continue

src_stat = src_path.lstat()
dst_stat = dst_path.lstat()
if src_path.is_dir() != dst_path.is_dir():
return True

src_stat = src_path.lstat()
dst_stat = dst_path.lstat()
if src_stat.st_mode != dst_stat.st_mode:
return True
if src_stat.st_uid != dst_stat.st_uid:
Expand Down Expand Up @@ -144,6 +148,26 @@ def set_permissions(
)


def compare_dirs(src: Path, dst: Path) -> bool:
"""Compare two directories recursively."""
comparison = filecmp.dircmp(src, dst)

changed = bool(
comparison.left_only
# or comparison.right_only # target may contain extra files
or comparison.diff_files
or comparison.funny_files
)
if changed:
return True

for subdir in comparison.common_dirs:
if compare_dirs(src / subdir, dst / subdir):
return True

return False


def run_module():
"""Run the Ansible module."""
module = AnsibleModule(
Expand Down Expand Up @@ -228,15 +252,9 @@ def run_module():

# determine if anything was changed
if target.exists():
comparison = filecmp.dircmp(temp_path, target)
comparison = compare_dirs(temp_path, target)
permissions = compare_permissions(temp_path, target)
changed = bool(
comparison.left_only
# or comparison.right_only # target contain have extra files
or comparison.diff_files
or comparison.funny_files
or permissions
)
changed = comparison or permissions
else:
changed = True
# merge source with target if anything changed
Expand Down
Loading