From 4c7ebaf5fea4b133a992f221c5553904984f3bcb Mon Sep 17 00:00:00 2001 From: KniveMaker App Date: Tue, 4 Mar 2025 09:01:59 +0000 Subject: [PATCH] small updates --- usr/local/bin/torrent-mover | 5 +++-- usr/local/lib/torrent-mover/common.sh | 22 ++++++++++++++++--- .../lib/torrent-mover/file_operations.sh | 2 +- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/usr/local/bin/torrent-mover b/usr/local/bin/torrent-mover index 1e044d1..19414fe 100755 --- a/usr/local/bin/torrent-mover +++ b/usr/local/bin/torrent-mover @@ -90,8 +90,9 @@ main() { if [[ ! -d "$dir" ]]; then log_info "Creating directory: $dir" if mkdir -p "$dir"; then - chmod 775 "$dir" - chown ${TORRENT_USER:-debian-transmission}:${TORRENT_GROUP:-debian-transmission} "$dir" + # Try to set permissions but don't fail if it doesn't work + chmod 775 "$dir" 2>/dev/null || log_warn "Could not set permissions on $dir" + chown ${TORRENT_USER:-debian-transmission}:${TORRENT_GROUP:-debian-transmission} "$dir" 2>/dev/null || log_warn "Could not set ownership on $dir" log_info "Created directory: $dir" else log_error "Failed to create directory: $dir" diff --git a/usr/local/lib/torrent-mover/common.sh b/usr/local/lib/torrent-mover/common.sh index bdf0aad..9a8ad31 100644 --- a/usr/local/lib/torrent-mover/common.sh +++ b/usr/local/lib/torrent-mover/common.sh @@ -215,15 +215,31 @@ run_in_transaction() { # validate_directories: Ensure required directories exist and are writable validate_directories() { local directories=("$@") + local error_count=0 + for dir in "${directories[@]}"; do + # Skip empty directory paths + if [[ -z "${dir}" ]]; then + continue + fi + if [[ ! -d "${dir}" ]]; then log_error "Directory missing: ${dir}" - return 1 + error_count=$((error_count + 1)) + continue fi + if [[ ! -w "${dir}" ]]; then - log_error "Write permission denied: ${dir}" - return 1 + log_warn "Write permission denied for: ${dir}" + log_warn "This may cause problems - the script will continue but operations may fail" + # Don't increment error_count to allow script to continue fi done + + if [[ ${error_count} -gt 0 ]]; then + log_error "${error_count} required directories are missing" + return 1 + fi + return 0 } \ No newline at end of file diff --git a/usr/local/lib/torrent-mover/file_operations.sh b/usr/local/lib/torrent-mover/file_operations.sh index 5d53120..ded30f3 100644 --- a/usr/local/lib/torrent-mover/file_operations.sh +++ b/usr/local/lib/torrent-mover/file_operations.sh @@ -25,7 +25,7 @@ generate_checksums() { # Skip if directory doesn't exist if [[ ! -d "${dir}" ]]; then return 1 - } + fi # Get the most recently modified file in the directory last_modified_file=$(find "${dir}" -type f ! \( -iname "*.nfo" -o -iname "*.sfv" \) -exec stat -c "%Y %n" {} \; | sort -nr | head -n1 | cut -d' ' -f2-)