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:
parent
bf41b9ad71
commit
e64e1115a7
@ -120,7 +120,10 @@ main() {
|
|||||||
torrent_ids=$(get_torrents)
|
torrent_ids=$(get_torrents)
|
||||||
log_debug "Found $(echo "$torrent_ids" | wc -l) torrents"
|
log_debug "Found $(echo "$torrent_ids" | wc -l) torrents"
|
||||||
|
|
||||||
echo "$torrent_ids" | while read -r id; do
|
# Use a regular for loop instead of a pipe to while
|
||||||
|
# to avoid the subshell issue that causes processed_source_dirs to be lost
|
||||||
|
readarray -t torrent_ids_array <<< "$torrent_ids"
|
||||||
|
for id in "${torrent_ids_array[@]}"; do
|
||||||
# Skip empty IDs
|
# Skip empty IDs
|
||||||
if [[ -z "$id" ]]; then
|
if [[ -z "$id" ]]; then
|
||||||
log_debug "Skipping empty torrent ID"
|
log_debug "Skipping empty torrent ID"
|
||||||
@ -244,6 +247,14 @@ main() {
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Print count of processed directories
|
||||||
|
if [[ "${DEBUG}" -eq 1 ]]; then
|
||||||
|
log_debug "Processed source directories count: ${#processed_source_dirs[@]}"
|
||||||
|
for dir in "${!processed_source_dirs[@]}"; do
|
||||||
|
log_debug "Processed directory: $dir"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
# Check disk usage for all directories
|
# Check disk usage for all directories
|
||||||
for dir in "${REQUIRED_DIRS[@]}"; do
|
for dir in "${REQUIRED_DIRS[@]}"; do
|
||||||
check_disk_usage "${dir}"
|
check_disk_usage "${dir}"
|
||||||
|
@ -13,18 +13,36 @@ get_destination() {
|
|||||||
|
|
||||||
# Check if path is already in the cache
|
# Check if path is already in the cache
|
||||||
if [[ -n "${PATH_CACHE["${source_path}"]+x}" ]]; then
|
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
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Skip recursive path analysis - only log once
|
# Skip recursive path analysis - only log once
|
||||||
if [[ "${source_path}" =~ ^/mnt/dsnas1/ ]]; then
|
if [[ "${source_path}" =~ ^/mnt/dsnas1/ ]]; then
|
||||||
# Already in destination format, return as is
|
# Already in destination format, return as is
|
||||||
|
log_debug "Path already in destination format: ${source_path}"
|
||||||
PATH_CACHE["${source_path}"]="${source_path}"
|
PATH_CACHE["${source_path}"]="${source_path}"
|
||||||
echo "${source_path}"
|
echo "${source_path}"
|
||||||
return
|
return
|
||||||
fi
|
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}"
|
log_info "Analyzing path: ${source_path}"
|
||||||
local destination="${DEFAULT_DST}"
|
local destination="${DEFAULT_DST}"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user