Sindbad~EG File Manager

Current Path : /home/beeson/public_html/WebMathXpert/ThreeBodyWeb/
Upload File :
Current File : //home/beeson/public_html/WebMathXpert/ThreeBodyWeb/RemoveStaleSVG.sh

#!/bin/bash

# Configuration
LOCAL_DB="ThreeBodyDatabase.db"
LOCAL_SVG_DIR="./images"

echo "Finding referenced sim_*.svg files in database..."
sqlite3 "$LOCAL_DB" "SELECT image_filename FROM documents WHERE image_filename LIKE 'sim_%.svg';" > svg_in_db.txt

# Build list of actual sim_*.svg files in the images directory
echo "Checking for stale SVGs in $LOCAL_SVG_DIR..."
find "$LOCAL_SVG_DIR" -maxdepth 1 -type f -name 'sim_*.svg' > svg_on_disk.txt

# Compare and delete stale files
while IFS= read -r file_path; do
    file_name=$(basename "$file_path")
    if ! grep -Fxq "$file_name" svg_in_db.txt; then
        echo "Deleting stale file: $file_name"
        rm -f "$file_path"
    fi
done < svg_on_disk.txt

# Cleanup
rm svg_in_db.txt svg_on_disk.txt

echo "Stale SVG cleanup completed on $(date)"

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists