From bf41b9ad7189bd34fb9cf5b466231b248a303085 Mon Sep 17 00:00:00 2001 From: masterdraco Date: Tue, 4 Mar 2025 18:03:53 +0100 Subject: [PATCH] Fixed infinite path mapping loop between dsnas1 and dsnas2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added path detection to prevent recursive analysis of paths already in destination format - Added special handling for same logical path on different mounts - Added early exit in process_copy for identical source and destination paths 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- usr/local/bin/torrent-mover | 11 +++++++++++ usr/local/lib/torrent-mover/file_operations.sh | 7 +++++++ usr/local/lib/torrent-mover/transmission_handler.sh | 9 +++++++++ 3 files changed, 27 insertions(+) diff --git a/usr/local/bin/torrent-mover b/usr/local/bin/torrent-mover index 11b0dd1..30ce6b1 100755 --- a/usr/local/bin/torrent-mover +++ b/usr/local/bin/torrent-mover @@ -191,6 +191,17 @@ main() { local dst dst=$(get_destination "${dir}") + # Detect same-path mappings (different mounts) + if [[ "${dir}" != "${dst}" && "${dir}" =~ ^/mnt/dsnas2/ && "${dst}" =~ ^/mnt/dsnas1/ ]]; then + local dir_suffix="${dir#/mnt/dsnas2/}" + local dst_suffix="${dst#/mnt/dsnas1/}" + if [[ "${dir_suffix}" == "${dst_suffix}" ]]; then + log_info "Source and destination are the same logical location with different mounts: ${dir_suffix}" + mark_processed "${hash}" + continue # Skip to next torrent + fi + fi + # Initialize warned_dirs for this directory if needed if [[ -n "${dir}" ]]; then [[ -z "${warned_dirs["${dir}"]+x}" ]] && warned_dirs["${dir}"]=0 diff --git a/usr/local/lib/torrent-mover/file_operations.sh b/usr/local/lib/torrent-mover/file_operations.sh index ded30f3..048e3b6 100644 --- a/usr/local/lib/torrent-mover/file_operations.sh +++ b/usr/local/lib/torrent-mover/file_operations.sh @@ -215,6 +215,13 @@ process_copy() { local id="$1" hash="$2" src="$3" dst="$4" local operation_result=0 + # Check if source and destination are the same or if we've already processed this + if [[ "${src}" == "${dst}" ]]; then + log_info "Source and destination are the same - skipping: ${src}" + mark_processed "${hash}" + return 0 + fi + if [[ ! -d "${src}" ]]; then log_error "Source directory missing: ${src}" return 1 diff --git a/usr/local/lib/torrent-mover/transmission_handler.sh b/usr/local/lib/torrent-mover/transmission_handler.sh index d8313a7..04cae11 100644 --- a/usr/local/lib/torrent-mover/transmission_handler.sh +++ b/usr/local/lib/torrent-mover/transmission_handler.sh @@ -11,11 +11,20 @@ get_destination() { return "${DEFAULT_DST}" fi + # Check if path is already in the cache if [[ -n "${PATH_CACHE["${source_path}"]+x}" ]]; then echo "${PATH_CACHE["${source_path}"]}" return fi + # Skip recursive path analysis - only log once + if [[ "${source_path}" =~ ^/mnt/dsnas1/ ]]; then + # Already in destination format, return as is + PATH_CACHE["${source_path}"]="${source_path}" + echo "${source_path}" + return + fi + log_info "Analyzing path: ${source_path}" local destination="${DEFAULT_DST}"