fix: pos media sync — strip all trailing slashes + mark partial sync
This commit is contained in:
+20
-9
@@ -69,13 +69,15 @@ while [[ $# -gt 0 ]]; do
|
||||
done
|
||||
[ "$MP3" -eq 1 ] || [ "$MP4" -eq 1 ] || { MP3=1; MP4=1; }
|
||||
|
||||
# Normalize a trailing slash on the source: GNU find strips it on the starting
|
||||
# point (find -H /x/ -type f emits /x/a.mp3, not /x//a.mp3), so with
|
||||
# SRC=/x/ the rel prefix "${f#"$SRC/"}" becomes /x// which never matches and
|
||||
# files would nest under <stick>/Music//x/... instead of mirroring the tree.
|
||||
# Covers both --source /x/ and MEDIA_SYNC_SOURCE=.../.
|
||||
SRC="${SRC%/}"
|
||||
[ -n "$SRC" ] || err "Source not found: $SRC"
|
||||
# Normalize trailing slashes on the source: GNU find normalizes ONE trailing
|
||||
# slash on the starting point (find -H /x/ -type f emits /x/a.mp3) but keeps
|
||||
# a doubled one (find -H /x// -type f emits /x//a.mp3), so with SRC=/x// the
|
||||
# rel prefix "${f#"$SRC/"}" never matches and files would nest under
|
||||
# <stick>/Music//x/... instead of mirroring the tree. Strip ALL trailing
|
||||
# slashes — a lone "/" or "//" ends up empty and hits the guard below.
|
||||
# Covers both --source /x// and MEDIA_SYNC_SOURCE=...//.
|
||||
while [[ "$SRC" == */ ]]; do SRC="${SRC%/}"; done
|
||||
[ -n "$SRC" ] || err "Source path is empty"
|
||||
|
||||
[ -d "$SRC" ] || err "Source not found: $SRC"
|
||||
|
||||
@@ -143,7 +145,12 @@ trap 'rm -f "$find_list" "$find_err"' EXIT
|
||||
find_rc=0
|
||||
find -H "$SRC" "${find_expr[@]}" >"$find_list" 2>"$find_err" || find_rc=$?
|
||||
sort -o "$find_list" "$find_list"
|
||||
# One "find reported problems" condition, computed once here and reused at the
|
||||
# final success messages (below) so a partial tree is never announced as fully
|
||||
# synced.
|
||||
find_ok=1
|
||||
if [ "$find_rc" -ne 0 ] || [ -s "$find_err" ]; then
|
||||
find_ok=0
|
||||
warn "find of the source reported problems — results may be incomplete:"
|
||||
if [ -s "$find_err" ]; then
|
||||
sed 's/^/ /' "$find_err"
|
||||
@@ -194,9 +201,13 @@ while IFS= read -r f; do
|
||||
fi
|
||||
done < "$find_list"
|
||||
|
||||
# Mark the success line + notification as partial when find reported
|
||||
# problems, so the success signal can't contradict the warning above.
|
||||
partial_suffix=""
|
||||
[ "$find_ok" -eq 0 ] && partial_suffix=" (partial — find reported problems)"
|
||||
if [ "$DRY_RUN" -eq 1 ]; then
|
||||
echo "DRY RUN — nothing copied. Would sync: ${added} new, ${updated} updated, ${unchanged} unchanged → $dest_root"
|
||||
else
|
||||
ok "Sync complete: ${added} added, ${updated} updated, ${unchanged} unchanged → $dest_root"
|
||||
notify_send "Music sync completed: ${added} added, ${updated} updated → $dest_root"
|
||||
ok "Sync complete: ${added} added, ${updated} updated, ${unchanged} unchanged → $dest_root$partial_suffix"
|
||||
notify_send "Music sync completed: ${added} added, ${updated} updated → $dest_root$partial_suffix"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user