Don't discard all previous cddbdata if a sed on cd-text data errors out
authorVille Skyttä <ville.skytta@iki.fi>
Sat, 2 Jan 2016 12:07:16 +0000 (14:07 +0200)
committerVille Skyttä <ville.skytta@iki.fi>
Sat, 2 Jan 2016 12:07:16 +0000 (14:07 +0200)
abcde

diff --git a/abcde b/abcde
index 9cf485a..080ed24 100755 (executable)
--- a/abcde
+++ b/abcde
@@ -2503,11 +2503,12 @@ do_cdtext ()
                TRACKM1=$(($TRACK - 1))
                TITLE="$(grep -E ^Track\ +$TRACK: "$ABCDETEMPDIR/cd-text" | tr -d \\r\\n | sed 's~^Track ..: .~~g;'"s~'$~~g")"
                echo "$TRACK: $TITLE" >> "$ABCDETEMPDIR/cddbchoices"
-               sed "s~^TTITLE${TRACKM1}=.*~TTITLE${TRACKM1}=${TITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new"
-               mv -f "$ABCDETEMPDIR/cddbread.new" "$ABCDETEMPDIR/cddbread.1"
+               sed "s~^TTITLE${TRACKM1}=.*~TTITLE${TRACKM1}=${TITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new" && \
+                       mv -f "$ABCDETEMPDIR/cddbread.new" "$ABCDETEMPDIR/cddbread.1"
        done
-       sed "s~^DTITLE=.*~DTITLE=${ATITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new"
-       mv -f "$ABCDETEMPDIR/cddbread.new" "$ABCDETEMPDIR/cddbread.1"
+       sed "s~^DTITLE=.*~DTITLE=${ATITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new" && \
+               mv -f "$ABCDETEMPDIR/cddbread.new" "$ABCDETEMPDIR/cddbread.1"
+       rm -f "$ABCDETEMPDIR/cddbread.new" # In case a sed error occurred
        echo >> "$ABCDETEMPDIR/cddbchoices"
        echo "cdtext-readcomplete" >> "$ABCDETEMPDIR/status"
 }