summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean Delvare <jdelvare@suse.de>2018-11-05 17:01:28 +0100
committerJean Delvare <jdelvare@suse.de>2018-11-05 17:01:28 +0100
commitcbde26f240a64bf6b4bd58951113e3524fc8db88 (patch)
tree5d0346cc9f649dde5e95644012f6f7ee1b12621d
parentc57dd873c7e0c917b53946c750e6694dc6bce022 (diff)
downloadquilt-cbde26f240a64bf6b4bd58951113e3524fc8db88.tar.gz
new: Fix series file corruption when trailing newline is missing
When editing the series file with certain editors, it is possible that no trailing newline character is present on the last line. In such case, adding a new patch at the end of the series would corrupt the series file. Prevent that by ensuring that a newline character is always present. This fixes the second issue reported in bug #54295: https://savannah.nongnu.org/bugs/?54295 Signed-off-by: Jean Delvare <jdelvare@suse.de>
-rw-r--r--quilt/scripts/patchfns.in7
-rw-r--r--test/missing-newline.test22
2 files changed, 29 insertions, 0 deletions
diff --git a/quilt/scripts/patchfns.in b/quilt/scripts/patchfns.in
index 0676399..902faf3 100644
--- a/quilt/scripts/patchfns.in
+++ b/quilt/scripts/patchfns.in
@@ -258,6 +258,13 @@ insert_in_series()
if [ -e "$SERIES" ]
then
cat "$SERIES" > $tmpfile
+
+ # Ensure there is a trailing newline before we append the rest
+ last_char=$(tail -c 1 "$tmpfile")
+ if ! [ -z "$last_char" -o "$last_char" = $'\n' -o "$last_char" = $'\r' ]
+ then
+ echo "" >> $tmpfile
+ fi
fi
echo "$patch$patch_args" >> $tmpfile
fi
diff --git a/test/missing-newline.test b/test/missing-newline.test
new file mode 100644
index 0000000..0b7abe7
--- /dev/null
+++ b/test/missing-newline.test
@@ -0,0 +1,22 @@
+$ mkdir patches
+
+$ echo foo > foo
+$ quilt new 1.patch
+> Patch %{P}1.patch is now on top
+
+$ quilt add foo
+> File foo added to patch %{P}1.patch
+
+$ echo bar > foo
+$ quilt refresh -p ab
+> Refreshed patch %{P}1.patch
+
+# Sabotage the series file
+$ echo -n 1.patch > patches/series
+
+# quilt should insert the missing newline before appending
+$ quilt new 2.patch
+> Patch %{P}2.patch is now on top
+$ cat patches/series
+> 1.patch
+> 2.patch