quilt-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Quilt-dev] [PATCH] Quote parameter to gen_tempfile as needed


From: Jean Delvare
Subject: [Quilt-dev] [PATCH] Quote parameter to gen_tempfile as needed
Date: Fri, 10 Jul 2020 10:18:37 +0200

When the parameter passed to gen_tempfile is based on the working
directory, we need to quote it because it could contain spaces or
other special characters. Also quote the string returned by this
function for the same reason.

Affected commands:
* quilt diff -z
* quilt fold
* quilt refresh -z
* quilt revert

Also test these code paths in the test suite to avoid regressions.

Signed-off-by: Jean Delvare <jdelvare@suse.de>
---
 quilt/diff.in               |    4 +-
 quilt/fold.in               |   10 +++----
 quilt/refresh.in            |    4 +-
 quilt/revert.in             |    6 ++--
 quilt/scripts/patchfns.in   |    6 ++--
 quilt/scripts/utilfns       |    4 +-
 test/space-in-work-dir.test |   59 ++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 76 insertions(+), 17 deletions(-)

--- quilt.orig/quilt/diff.in    2020-07-06 11:08:00.085446020 +0200
+++ quilt/quilt/diff.in 2020-07-06 11:54:21.420006927 +0200
@@ -129,7 +129,7 @@ die()
 {
        local status=$1
        [ -e "$tmp_files" ] && rm -f $tmp_files
-       [ -n "$workdir" ] && rm -rf $workdir
+       [ -n "$workdir" ] && rm -rf "$workdir"
        exit $status
 }
 
@@ -323,7 +323,7 @@ IFS=$saved_IFS
 
 if [ -n "$opt_relative" ]
 then
-       workdir=$(gen_tempfile -d $PWD/quilt)
+       workdir=$(gen_tempfile -d "$PWD/quilt")
        apply_patch_temporarily "$workdir" "$last_patch" "${files[@]}" \
        || die 1
 fi
--- quilt.orig/quilt/fold.in    2020-07-06 11:08:00.085446020 +0200
+++ quilt/quilt/fold.in 2020-07-06 11:53:22.157312696 +0200
@@ -89,7 +89,7 @@ top=$(find_top_patch) || exit 1
 
 trap "failed=1" SIGINT
 
-workdir=$(gen_tempfile -d $PWD)
+workdir=$(gen_tempfile -d "$PWD")
 patch -d ${SUBDIR:-.} $QUILT_PATCH_OPTS -p$opt_strip_level \
       --backup --prefix="$workdir/$SUBDIR" $patch_args \
 || failed=1
@@ -102,7 +102,7 @@ if [ -z "$failed" ]
 then
        # Copy additional files from workdir to the backup directory
        # For this patch
-       for file in $(find $workdir -type f -a ! -path "$workdir/.timestamp")
+       for file in $(find "$workdir" -type f -a ! -path "$workdir/.timestamp")
        do
                file="${file:${#workdir}+1}"
                backup_file="$(backup_file_name $top "$file")"
@@ -120,7 +120,7 @@ fi
 if [ -n "$failed" ]
 then
        # Restore all files to the state from before applying the patch
-       for file in $(find $workdir -type f -a ! -path "$workdir/.timestamp")
+       for file in $(find "$workdir" -type f -a ! -path "$workdir/.timestamp")
        do
                file="${file:${#workdir}+1}"
                if ! mv -f "$workdir/$file" "$file"
@@ -128,12 +128,12 @@ then
                        printf $"File %s may be corrupted\n" "$file" >&2
                fi
        done
-       rm -rf $workdir
+       rm -rf "$workdir"
        exit 1
 fi
 IFS=$saved_IFS
 
-rm -rf $workdir
+rm -rf "$workdir"
 exit 0
 ### Local Variables:
 ### mode: shell-script
--- quilt.orig/quilt/refresh.in 2020-07-06 11:08:00.087446043 +0200
+++ quilt/quilt/refresh.in      2020-07-06 11:54:06.905836902 +0200
@@ -80,7 +80,7 @@ die()
        local status=$1
        [ -n "$tmp_patch" ] && rm -f $tmp_patch
        [ -n "$tmp_result" ] && rm -f $tmp_result
-       [ -n "$workdir" ] && rm -rf $workdir
+       [ -n "$workdir" ] && rm -rf "$workdir"
        exit $status
 }
 
@@ -205,7 +205,7 @@ esac
 trap "die 1" SIGTERM
 
 if [ -n "$opt_fork" ]; then
-       workdir=$(gen_tempfile -d $PWD/quilt)
+       workdir=$(gen_tempfile -d "$PWD/quilt")
        apply_patch_temporarily "$workdir" "$old_patch" || exit 1
 fi
 
--- quilt.orig/quilt/revert.in  2020-07-06 11:08:00.088446055 +0200
+++ quilt/quilt/revert.in       2020-07-06 11:52:31.276716645 +0200
@@ -86,9 +86,9 @@ do
 done
 [ $status -eq 0 ] || exit $status
 
-workdir=$(gen_tempfile -d $PWD)
-add_exit_handler "rm -rf $workdir"
-apply_patch_temporarily $workdir $patch "${@/#/$SUBDIR}" || exit 1
+workdir=$(gen_tempfile -d "$PWD")
+add_exit_handler "rm -rf \"$workdir\""
+apply_patch_temporarily "$workdir" $patch "${@/#/$SUBDIR}" || exit 1
 
 for file in ${*/#/$SUBDIR}
 do
--- quilt.orig/quilt/scripts/patchfns.in        2020-07-06 11:08:01.359460816 
+0200
+++ quilt/quilt/scripts/patchfns.in     2020-07-06 11:20:08.099935398 +0200
@@ -920,8 +920,8 @@ apply_patch_temporarily()
 
        local prefix=$QUILT_PC/$patch/
        [ ${prefix:0:1} == / ] || prefix=$PWD/$prefix
-       if ! ( cd $workdir && \
-              $QUILT_DIR/scripts/backup-files -B $prefix -r -k -s "${@:--}" )
+       if ! ( cd "$workdir" && \
+              $QUILT_DIR/scripts/backup-files -B "$prefix" -r -k -s "${@:--}" )
        then
                printf $"Failed to copy files to temporary directory\n" >&2
                return 1
@@ -930,7 +930,7 @@ apply_patch_temporarily()
        if [ -s $patch_file ]
        then
                if ! cat_file $patch_file \
-                    | patch -d $workdir $QUILT_PATCH_OPTS $patch_args \
+                    | patch -d "$workdir" $QUILT_PATCH_OPTS $patch_args \
                             --no-backup-if-mismatch -f \
                             >/dev/null 2>/dev/null
                then
--- quilt.orig/quilt/scripts/utilfns    2020-07-06 11:00:10.490992420 +0200
+++ quilt/quilt/scripts/utilfns 2020-07-06 11:14:36.404054160 +0200
@@ -47,8 +47,8 @@ gen_tempfile()
 {
        if [ "$1" = -d ]
        then
-               mktemp -d ${2:-${TMPDIR:-/tmp}/quilt.}XXXXXX
+               mktemp -d "${2:-${TMPDIR:-/tmp}/quilt.}XXXXXX"
        else
-               mktemp ${1:-${TMPDIR:-/tmp}/quilt.}XXXXXX
+               mktemp "${1:-${TMPDIR:-/tmp}/quilt.}XXXXXX"
        fi
 }
--- quilt.orig/test/space-in-work-dir.test      2020-07-06 11:57:25.376161870 
+0200
+++ quilt/test/space-in-work-dir.test   2020-07-10 10:02:52.779489549 +0200
@@ -27,9 +27,49 @@ $ cat patches/1.patch
 > -old
 > +new
 
+$ echo newer > a
+$ quilt diff -z
+> Index: project/a
+> ===================================================================
+> --- project.orig/a
+> +++ project/a
+> @@ -1 +1 @@
+> -new
+> +newer
+
+$ quilt revert a
+> Changes to a in patch patches/1.patch reverted
+$ quilt diff -z
+$ echo newer > a
+
+$ quilt refresh -z
+> Fork of patch patches/1.patch created as patches/1-2.patch
+$ quilt series
+> patches/1.patch
+> patches/1-2.patch
+$ cat patches/1.patch
+> Index: project/a
+> ===================================================================
+> --- project.orig/a
+> +++ project/a
+> @@ -1 +1 @@
+> -old
+> +new
+$ cat patches/1-2.patch
+> Index: project/a
+> ===================================================================
+> --- project.orig/a
+> +++ project/a
+> @@ -1 +1 @@
+> -new
+> +newer
+
 # Running a command when not at the root of the project tests additional
 # code paths
 $ cd subdir
+$ quilt pop -q
+> Removing patch ../patches/1-2.patch
+> Now at patch ../patches/1.patch
 $ quilt diff --no-index
 > --- project.orig/a
 > +++ project/a
@@ -55,6 +95,25 @@ $ quilt top
 
 $ quilt series -v
 > = patches/1.patch
+>   patches/1-2.patch
+
+$ quilt fold < patches/1-2.patch
+> patching file a
+
+$ quilt diff -z
+> Index: project/a
+> ===================================================================
+> --- project.orig/a
+> +++ project/a
+> @@ -1 +1 @@
+> -new
+> +newer
+
+$ quilt refresh
+> Refreshed patch patches/1.patch
+
+$ quilt delete -rn
+> Removed patch patches/1-2.patch
 
 $ quilt remove a
 > File a removed from patch patches/1.patch


-- 
Jean Delvare
SUSE L3 Support



reply via email to

[Prev in Thread] Current Thread [Next in Thread]