mirror of
https://github.com/acedanger/shell.git
synced 2025-12-06 05:40:11 -08:00
feat: Improve checksum calculation by using a temporary cache directory and enhancing permission handling; fixes permission denied error
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user