From 82b4976efb012a748bdc7ceccd75c151ed2d3990 Mon Sep 17 00:00:00 2001 From: veclav talica Date: Sat, 10 Feb 2024 22:15:32 +0500 Subject: [PATCH] checksum based cache for neocities uploads --- .gitignore | 1 + upload.sh | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index b47985c..bec3509 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ html/ **/.*/ **/*.jpg/ **/*.png/ +**/*.upload-checksum diff --git a/upload.sh b/upload.sh index e6cd5db..e1ae128 100755 --- a/upload.sh +++ b/upload.sh @@ -1,12 +1,15 @@ #!/usr/bin/bash -# todo: Create local cache containing file timestamps that were previously uploaded. - for cur in ./html/{*,*/*,*/*/*}; do - if [[ "$cur" == *"/tracks/"* ]]; then - continue - fi - if [ -f "$cur" ]; then + if [ -f "$cur" ] && [[ ! "$cur" == *.upload-checksum ]]; then + if [ -f "$cur.upload-checksum" ]; then + c=$(cat "$cur.upload-checksum" | sha256sum -c 2> /dev/null) + if [[ "$c" == *OK ]]; then + echo "$cur is up-to-date, skipping" + continue + fi + fi + echo $(sha256sum "$cur") > "$cur.upload-checksum" d=$(dirname $(realpath --relative-to="./html" "$cur")) if [[ "$d" == "." ]]; then neocities upload $cur