🔨 Keep DEST_DIR and SOURCE_DIR in sync

This commit is contained in:
Gal 2024-02-14 22:42:14 +01:00
parent 1c2996acc4
commit aae3847a46
Signed by: gal
GPG Key ID: F035BC65003BC00B
1 changed files with 2 additions and 15 deletions

View File

@ -69,21 +69,8 @@ find -L "$SOURCE_DIR" -type f -name "*.md" -exec grep -q "publish: true" {} \; -
fi
done
# Log the script execution
echo "Executing cleanup script at $(date)"
# Find files in DEST_DIR that don't exist in SOURCE_DIR and delete them
find "$DEST_DIR" -type f -exec sh -c '
relative_path=${1#$DEST_DIR/}
source_file="$SOURCE_DIR/$relative_path"
if [ ! -e "$source_file" ]; then
echo "Deleting $1 as it doesn't exist in SOURCE_DIR"
rm "$1"
else
echo "Skipping $1 as it exists in SOURCE_DIR"
fi
' _ {} \;
# Delete files in DEST_DIR that don't exist in SOURCE_DIR anymore
find "$DEST_DIR" -type f -exec sh -c '[ ! -e "$SOURCE_DIR/${1#$DEST_DIR/}" ] && rm "$1"' _ {} \;
# Print the log file
cat "$LOG_FILE"