diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..751553b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.bak diff --git a/locksync.ash b/locksync.ash index 9b71d2e..748b232 100644 --- a/locksync.ash +++ b/locksync.ash @@ -5,24 +5,23 @@ export REMOTE_BASE="RCLONE_PREFIX" export LOG_FILE="/recalbox/share/system/logs/locksync.log" log() { - # $1 = level - # $2 = message - touch "$LOG_FILE" + # Ensure log directory exists + mkdir -p "$(dirname "$LOG_FILE")" printf "[%s] [%s] %s\n" "$(date '+%Y-%m-%d %H:%M:%S')" "$1" "$2" >>"$LOG_FILE" } -locks="$(find /recalbox/share/saves -name "*.lock")" -if [ -z "$locks" ]; then - log "INFO" "No game locks found" -else - while read -r lockfile; do - lgame="$(echo "$lockfile" | sed 's/\.lock//')" - rgame="$(echo "$lockfile" | sed 's|/recalbox/share/roms/||' | sed 's/\.lock//')" - if [ -f "$lgame" ]; then - log "INFO" "Game found: $lgame" - else - continue - fi +# Use find to pipe directly into the loop to handle spaces in filenames correctly +find /recalbox/share/saves -name "*.lock" | while read -r lockfile; do + # 1. Get the game path by removing .lock + lgame="${lockfile%.lock}" + + # 2. Extract the relative path for the remote + # This removes '/recalbox/share/saves/' from the start of the path + rgame="${lgame#/recalbox/share/saves/}" + + if [ -f "$lgame" ]; then + log "INFO" "Game found: $lgame" + if rclone copyto "$lgame" "${REMOTE_BASE}/${rgame}"; then log "INFO" "Game synced: $rgame" rm "$lockfile" @@ -30,5 +29,7 @@ else log "WARN" "Could not sync game $rgame" log "INFO" "Lockfile $lockfile not removed" fi - done <"$locks" -fi + else + log "DEBUG" "Lock found for non-existent file: $lgame" + fi +done