summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--quilt/scripts/patchfns.in5
-rw-r--r--test/symlink.test48
2 files changed, 52 insertions, 1 deletions
diff --git a/quilt/scripts/patchfns.in b/quilt/scripts/patchfns.in
index f7100b7..efb6e8e 100644
--- a/quilt/scripts/patchfns.in
+++ b/quilt/scripts/patchfns.in
@@ -785,7 +785,10 @@ cat_to_new_file()
{
local filename="$1"
- if [ -e "$filename" -a ! -L "$filename" ]
+ # If the destination file is a symbolic link, preserve it unless its
+ # target is read-only. In other cases, delete the patch file first in
+ # case it has hard links.
+ if [ -e "$filename" -a ! \( -L "$filename" -a -w "$filename" \) ]
then
rm -f "$filename"
fi
diff --git a/test/symlink.test b/test/symlink.test
index 9e5e797..4610af6 100644
--- a/test/symlink.test
+++ b/test/symlink.test
@@ -51,3 +51,51 @@
> @@ -1 +1 @@
> -foo
> +foo changed 2
+
+# Test the refresh when target is read-only
+ $ chmod -w test.diff
+ $ echo "foo changed 4" > foo
+ $ quilt refresh --no-index -p ab
+ > Refreshed patch patches/test.diff
+
+ $ readlink patches/test.diff
+ $ echo %{?}
+ > 1
+
+ $ cat patches/test.diff
+ > --- a/foo
+ > +++ b/foo
+ > @@ -1 +1 @@
+ > -foo
+ > +foo changed 4
+
+# Test the refresh --backup when target is read-only
+ $ mv patches/test.diff .
+ $ ln -s ../test.diff patches/test.diff
+ $ chmod -w test.diff
+
+ $ echo "foo changed 5" > foo
+ $ quilt refresh --backup --no-index -p ab
+ > Refreshed patch patches/test.diff
+
+ $ readlink patches/test.diff
+ $ echo %{?}
+ > 1
+
+ $ cat patches/test.diff
+ > --- a/foo
+ > +++ b/foo
+ > @@ -1 +1 @@
+ > -foo
+ > +foo changed 5
+
+ $ readlink patches/test.diff~
+ $ echo %{?}
+ > 1
+
+ $ cat patches/test.diff~
+ > --- a/foo
+ > +++ b/foo
+ > @@ -1 +1 @@
+ > -foo
+ > +foo changed 4