[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Quilt-dev] [PATCH] Quote series file name everywhere
From: |
Jean Delvare |
Subject: |
[Quilt-dev] [PATCH] Quote series file name everywhere |
Date: |
Tue, 9 May 2017 17:05:43 +0200 |
Don't choke if the series file name contains a space or any other
special character. "$SERIES" was already quoted in various places, do
it consistently so that quilt will work in this situation. And add a
basic test case to verify that it actually works.
Signed-off-by: Jean Delvare <address@hidden>
---
quilt/scripts/patchfns.in | 36 +++++-----
test/space-in-series.test | 151 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 169 insertions(+), 18 deletions(-)
--- quilt.orig/quilt/scripts/patchfns.in 2017-05-02 15:02:55.987641611
+0200
+++ quilt/quilt/scripts/patchfns.in 2017-05-09 16:58:59.209298113 +0200
@@ -118,7 +118,7 @@ patch_args()
{
local patch=$1
- if [ -e $SERIES ]
+ if [ -e "$SERIES" ]
then
awk '
{sub(/(^|[ \t]+)#.*/, "") }
@@ -133,7 +133,7 @@ patch_args()
print "-p1" ;
exit
}
- ' $SERIES
+ ' "$SERIES"
fi
}
@@ -163,7 +163,7 @@ change_db_strip_level()
level=""
fi
- if [ -e $SERIES ]
+ if [ -e "$SERIES" ]
then
local tmpfile=$(gen_tempfile)
awk '
@@ -198,10 +198,10 @@ change_db_strip_level()
insert_arg(2, "'"$level"'")
}
{ print }
- ' $SERIES > $tmpfile
- if ! cmp $SERIES $tmpfile >/dev/null 2>/dev/null
+ ' "$SERIES" > $tmpfile
+ if ! cmp "$SERIES" $tmpfile >/dev/null 2>/dev/null
then
- cat $tmpfile > $SERIES
+ cat $tmpfile > "$SERIES"
fi
rm -f $tmpfile
else
@@ -213,9 +213,9 @@ patch_in_series()
{
local patch=$1
- if [ -e $SERIES ]
+ if [ -e "$SERIES" ]
then
- grep -q "^$(quote_bre $patch)\([ \t]\|$\)" $SERIES
+ grep -q "^$(quote_bre $patch)\([ \t]\|$\)" "$SERIES"
else
return 1
fi
@@ -240,7 +240,7 @@ insert_in_series()
fi
tmpfile=$(gen_tempfile) || return 1
- mkdir -p $(dirname $SERIES)
+ mkdir -p "$(dirname "$SERIES")"
if [ -n "$before" ]
then
awk '
@@ -273,13 +273,13 @@ remove_from_series()
awk '
! /^'"$(quote_re $patch)"'([ \t]|$)/ \
{ print }
- ' $SERIES > $tmpfile
+ ' "$SERIES" > $tmpfile
if [ $? -ne 0 ]
then
rm -f $tmpfile
return 1
fi
- cat $tmpfile > $SERIES
+ cat $tmpfile > "$SERIES"
rm -f $tmpfile
}
@@ -294,13 +294,13 @@ rename_in_series()
good=1 }
{ print }
END { exit(! good) }
- ' $SERIES > $tmpfile
+ ' "$SERIES" > $tmpfile
if [ $? -ne 0 ]
then
rm -f $tmpfile
return 1
fi
- cat $tmpfile > $SERIES
+ cat $tmpfile > "$SERIES"
rm -f $tmpfile
}
@@ -338,10 +338,10 @@ backup_file_name()
cat_series()
{
- if [ -e $SERIES ]
+ if [ -e "$SERIES" ]
then
sed -e '/^#/d' -e 's/^[ '$'\t'']*//' \
- -e 's/[ '$'\t''].*//' -e '/^$/d' $SERIES
+ -e 's/[ '$'\t''].*//' -e '/^$/d' "$SERIES"
else
return 1
fi
@@ -529,7 +529,7 @@ find_patch()
local patch=${1#$SUBDIR_DOWN$QUILT_PATCHES/}
local bre=$(quote_bre "$patch")
set -- $(sed -e
"/^$bre\(\|\.patch\|\.diff\?\)\(\|\.gz\|\.bz2\|\.xz\|\.lzma\)\([
"$'\t'"]\|$\)/!d" \
- -e 's/[ '$'\t''].*//' $SERIES)
+ -e 's/[ '$'\t''].*//' "$SERIES")
if [ $# -eq 1 ]
then
echo $1
@@ -1146,10 +1146,10 @@ fi
if [ "${QUILT_SERIES:0:1}" = / ]
then
SERIES=$QUILT_SERIES
-elif [ -f $QUILT_PC/$QUILT_SERIES ]
+elif [ -f "$QUILT_PC/$QUILT_SERIES" ]
then
SERIES=$QUILT_PC/$QUILT_SERIES
-elif [ -f $QUILT_SERIES ]
+elif [ -f "$QUILT_SERIES" ]
then
SERIES=$QUILT_SERIES
else
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ quilt/test/space-in-series.test 2017-05-09 16:59:39.093765309 +0200
@@ -0,0 +1,151 @@
+This test case was originally created as a copy of example1, but where
+the series file name contains a space.
+
+ $ export QUILT_SERIES="quilt series"
+
+The text used here was taken from:
+http://the-tech.mit.edu/Shakespeare/midsummer/full.html
+
+ $ mkdir patches
+
+ $ cat > Oberon.txt
+ < Yet mark'd I where the bolt of Cupid fell:
+ < It fell upon a little western flower,
+ < Before milk-white, now purple with love's wound,
+ < And girls call it love-in-idleness.
+
+ $ quilt new flower.diff
+ > Patch %{P}flower.diff is now on top
+
+ $ quilt files
+ $ quilt add Oberon.txt
+ > File Oberon.txt added to patch %{P}flower.diff
+
+ $ cat >> Oberon.txt
+ < The juice of it on sleeping eye-lids laid
+ < Will make a man or woman madly dote
+ < Upon the next live creature that it sees.
+
+Or ``quilt edit Oberon.txt''
+
+ $ quilt refresh -p ab
+ > Refreshed patch %{P}flower.diff
+
+ $ cat patches/flower.diff
+ > Index: b/Oberon.txt
+ > ===================================================================
+ > --- a/Oberon.txt
+ > +++ b/Oberon.txt
+ > @@ -2,3 +2,6 @@
+ > It fell upon a little western flower,
+ > Before milk-white, now purple with love's wound,
+ > And girls call it love-in-idleness.
+ > +The juice of it on sleeping eye-lids laid
+ > +Will make a man or woman madly dote
+ > +Upon the next live creature that it sees.
+
+ $ sed -ne '1,4p' Oberon.txt > Oberon.new
+ $ echo "Fetch me that flower; the herb I shew'd thee once:" >>
Oberon.new
+ $ sed -e '1,4d' Oberon.txt >> Oberon.new
+ $ mv Oberon.new Oberon.txt
+ $ quilt diff -z -p ab
+ > Index: b/Oberon.txt
+ > ===================================================================
+ > --- a/Oberon.txt
+ > +++ b/Oberon.txt
+ > @@ -2,6 +2,7 @@
+ > It fell upon a little western flower,
+ > Before milk-white, now purple with love's wound,
+ > And girls call it love-in-idleness.
+ > +Fetch me that flower; the herb I shew'd thee once:
+ > The juice of it on sleeping eye-lids laid
+ > Will make a man or woman madly dote
+ > Upon the next live creature that it sees.
+
+ $ quilt diff -p ab
+ > Index: b/Oberon.txt
+ > ===================================================================
+ > --- a/Oberon.txt
+ > +++ b/Oberon.txt
+ > @@ -2,3 +2,7 @@
+ > It fell upon a little western flower,
+ > Before milk-white, now purple with love's wound,
+ > And girls call it love-in-idleness.
+ > +Fetch me that flower; the herb I shew'd thee once:
+ > +The juice of it on sleeping eye-lids laid
+ > +Will make a man or woman madly dote
+ > +Upon the next live creature that it sees.
+
+ $ quilt refresh
+ > Refreshed patch %{P}flower.diff
+
+ $ quilt top
+ > %{P}flower.diff
+
+ $ quilt files
+ > Oberon.txt
+
+ $ quilt patches Oberon.txt
+ > %{P}flower.diff
+ $ quilt pop -f
+ > Removing patch %{P}flower.diff
+ > Restoring Oberon.txt
+ >
+ > No patches applied
+
+ $ quilt files patches/flower.diff
+ > Oberon.txt
+
+ $ sed -e "s/girls/maidens/" Oberon.txt > Oberon.new
+ $ mv Oberon.new Oberon.txt
+ $ quilt push
+ > Applying patch %{P}flower.diff
+ >~ patching file `?Oberon.txt'?
+ > Hunk #1 FAILED at 2.
+ >~ 1 out of 1 hunk FAILED -- rejects in file `?Oberon.txt'?
+ > Patch %{P}flower.diff does not apply (enforce with -f)
+
+ $ quilt push -f
+ > Applying patch %{P}flower.diff
+ >~ patching file `?Oberon.txt'?
+ > Hunk #1 FAILED at 2.
+ >~ 1 out of 1 hunk FAILED -- saving rejects to (file
)?`?Oberon.txt.rej'?
+ > Applied patch %{P}flower.diff (forced; needs refresh)
+
+ $ cat >> Oberon.txt
+ < Fetch me that flower; the herb I shew'd thee once:
+ < The juice of it on sleeping eye-lids laid
+ < Will make a man or woman madly dote
+ < Upon the next live creature that it sees.
+
+ $ quilt refresh -p ab
+ > Refreshed patch %{P}flower.diff
+ $ rm -f Oberon.txt.rej
+
+ $ cat Oberon.txt
+ > Yet mark'd I where the bolt of Cupid fell:
+ > It fell upon a little western flower,
+ > Before milk-white, now purple with love's wound,
+ > And maidens call it love-in-idleness.
+ > Fetch me that flower; the herb I shew'd thee once:
+ > The juice of it on sleeping eye-lids laid
+ > Will make a man or woman madly dote
+ > Upon the next live creature that it sees.
+
+ $ cat patches/flower.diff
+ > Index: b/Oberon.txt
+ > ===================================================================
+ > --- a/Oberon.txt
+ > +++ b/Oberon.txt
+ > @@ -2,3 +2,7 @@
+ > It fell upon a little western flower,
+ > Before milk-white, now purple with love's wound,
+ > And maidens call it love-in-idleness.
+ > +Fetch me that flower; the herb I shew'd thee once:
+ > +The juice of it on sleeping eye-lids laid
+ > +Will make a man or woman madly dote
+ > +Upon the next live creature that it sees.
+
+ $ quilt grep love
+ > Oberon.txt:Before milk-white, now purple with love's wound,
+ > Oberon.txt:And maidens call it love-in-idleness.
--
Jean Delvare
SUSE L3 Support
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Quilt-dev] [PATCH] Quote series file name everywhere,
Jean Delvare <=