[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Quilt-dev] [PATCH 1/2] new: Fix series file corruption when trailing ne
From: |
Jean Delvare |
Subject: |
[Quilt-dev] [PATCH 1/2] new: Fix series file corruption when trailing newline is missing |
Date: |
Tue, 9 Oct 2018 16:14:50 +0200 |
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 <address@hidden>
---
quilt/scripts/patchfns.in | 7 +++++++
test/missing-newline.test | 22 ++++++++++++++++++++++
2 files changed, 29 insertions(+)
--- quilt.orig/quilt/scripts/patchfns.in 2018-10-04 11:40:43.162325693
+0200
+++ quilt/quilt/scripts/patchfns.in 2018-10-04 11:41:28.170856471 +0200
@@ -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
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ quilt/test/missing-newline.test 2018-10-04 11:41:32.420906613 +0200
@@ -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
--
Jean Delvare
SUSE L3 Support
- [Quilt-dev] [PATCH 1/2] new: Fix series file corruption when trailing newline is missing,
Jean Delvare <=