Fixed path mapping persistence and repeated logging issues
- Changed while loop with pipe to readarray with for loop to preserve variable state - Enhanced path detection to better handle identical structures across mounts - Added debug logging for path cache hits to trace execution - Added debug output for processed directories at the end of execution 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -13,18 +13,36 @@ get_destination() {
|
||||
|
||||
# Check if path is already in the cache
|
||||
if [[ -n "${PATH_CACHE["${source_path}"]+x}" ]]; then
|
||||
echo "${PATH_CACHE["${source_path}"]}"
|
||||
local cached_destination="${PATH_CACHE["${source_path}"]}"
|
||||
log_debug "Using cached destination for ${source_path}: ${cached_destination}"
|
||||
echo "${cached_destination}"
|
||||
return
|
||||
fi
|
||||
|
||||
# Skip recursive path analysis - only log once
|
||||
if [[ "${source_path}" =~ ^/mnt/dsnas1/ ]]; then
|
||||
# Already in destination format, return as is
|
||||
log_debug "Path already in destination format: ${source_path}"
|
||||
PATH_CACHE["${source_path}"]="${source_path}"
|
||||
echo "${source_path}"
|
||||
return
|
||||
fi
|
||||
|
||||
# For paths in dsnas2, check if they map to same structure in dsnas1
|
||||
if [[ "${source_path}" =~ ^/mnt/dsnas2/ ]]; then
|
||||
local dir_suffix="${source_path#/mnt/dsnas2/}"
|
||||
local potential_dest="/mnt/dsnas1/${dir_suffix}"
|
||||
|
||||
# If the directories match exactly in structure, only on different mounts,
|
||||
# return the source to avoid needless copying
|
||||
if [[ -d "${potential_dest}" ]]; then
|
||||
log_debug "Path maps to same structure on different mount: ${source_path} -> ${source_path}"
|
||||
PATH_CACHE["${source_path}"]="${source_path}"
|
||||
echo "${source_path}"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
log_info "Analyzing path: ${source_path}"
|
||||
local destination="${DEFAULT_DST}"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user