feat: Improve checksum calculation by using a temporary cache directory and enhancing permission handling; fixes permission denied error

This commit is contained in:
Peter Wood
2025-05-26 15:05:39 -04:00
parent 632c4cc702
commit aa5fb5bb2f

View File

@@ -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