From aa5fb5bb2f73f77e7d33879deea7583c1acc5838 Mon Sep 17 00:00:00 2001 From: Peter Wood Date: Mon, 26 May 2025 15:05:39 -0400 Subject: [PATCH] feat: Improve checksum calculation by using a temporary cache directory and enhancing permission handling; fixes permission denied error --- plex/backup-plex.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plex/backup-plex.sh b/plex/backup-plex.sh index fc3f5a9..f2da595 100755 --- a/plex/backup-plex.sh +++ b/plex/backup-plex.sh @@ -230,9 +230,14 @@ send_notification() { # Enhanced checksum calculation with caching calculate_checksum() { local file="$1" - local cache_file="${file}.md5" + # Use /tmp for cache files to avoid permission issues + local cache_dir="/tmp/plex-backup-cache" + local cache_file="$cache_dir/$(echo "$file" | sed 's|/|_|g').md5" local file_mtime=$(stat -c %Y "$file" 2>/dev/null || echo "0") + # Create cache directory if it doesn't exist + mkdir -p "$cache_dir" 2>/dev/null || true + # Check if cached checksum exists and is newer than file if [ -f "$cache_file" ]; then local cache_mtime=$(stat -c %Y "$cache_file" 2>/dev/null || echo "0") @@ -263,7 +268,7 @@ calculate_checksum() { # Check if sudo checksum is valid if [[ -n "$checksum" && "$checksum" =~ ^[a-f0-9]{32}$ ]]; then # Cache the checksum with appropriate permissions - sudo bash -c "echo '$checksum' > '$cache_file'" 2>/dev/null || true + echo "$checksum" | sudo tee "$cache_file" >/dev/null 2>&1 || true echo "$checksum" return 0 fi