summaryrefslogtreecommitdiff
path: root/tests/symlinks
diff options
context:
space:
mode:
authorAndreas Gruenbacher <agruen@suse.de>2010-04-26 19:01:08 +0200
committerAndreas Gruenbacher <agruen@suse.de>2010-04-27 12:38:15 +0200
commite3cfef7f99cdecd072829003ef5eb5aa92ea23f1 (patch)
tree09a72fa92c7ae1af67eeb43c8a5f1526f70f32f0 /tests/symlinks
parentf558fff53365dd4fb315966f059160d3d2ece603 (diff)
downloadpatch-e3cfef7f99cdecd072829003ef5eb5aa92ea23f1.tar.gz
Refuse to patch symlinks
* src/inp.c (get_input_file), src/pch.c (there_is_another_patch, intuit_diff_type): Use lstat instead of stat. This causes patch to refuse patching symlinks (get_input_file() will refuse to read them). * src/util.c (create_backup): Refuse to create backups of symlinks. * tests/symlinks: New test case. * tests/Makefile.am (TESTS): Add test case. * bootstrap.conf: Use the gnulib lstat module.
Diffstat (limited to 'tests/symlinks')
-rw-r--r--tests/symlinks76
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/symlinks b/tests/symlinks
new file mode 100644
index 0000000..3472791
--- /dev/null
+++ b/tests/symlinks
@@ -0,0 +1,76 @@
+# Copyright (C) 2010 Free Software Foundation, Inc.
+#
+# Copying and distribution of this file, with or without modification,
+# in any medium, are permitted without royalty provided the copyright
+# notice and this notice are preserved.
+
+# Symlink related tests
+
+. $srcdir/test-lib.sh
+
+require_cat
+use_local_patch
+use_tmpdir
+
+# ==============================================================
+
+cat > create.diff <<EOF
+--- /dev/null
++++ l
+@@ -0,0 +1 @@
++one
+EOF
+
+rm -f f l
+echo f > f
+ncheck 'ln -s f l'
+
+check 'patch < create.diff || echo "Status: $?"' <<EOF
+File l is not a regular file -- can't patch
+1 out of 1 hunk ignored -- saving rejects to file l.rej
+Status: 1
+EOF
+
+check 'cat f' <<EOF
+f
+EOF
+
+# --------------------------------------------------------------
+
+rm -f f l
+echo f > f
+ncheck 'ln -s f l'
+
+cat > modify.diff <<EOF
+--- l
++++ l
+@@ -1 +1 @@
+-one
++two
+EOF
+
+check 'patch < modify.diff || echo "Status: $?"' <<EOF
+File l is not a regular file -- can't patch
+1 out of 1 hunk ignored -- saving rejects to file l.rej
+Status: 1
+EOF
+# --------------------------------------------------------------
+
+rm -f f l
+echo f > f
+ncheck 'ln -s f l'
+
+cat > delete.diff <<EOF
+--- l
++++ /dev/null
+@@ -1 +0,0 @@
+-one
+EOF
+
+check 'patch < delete.diff || echo "Status: $?"' <<EOF
+File l is not a regular file -- can't patch
+1 out of 1 hunk ignored -- saving rejects to file l.rej
+Status: 1
+EOF
+
+# FIXME: Add tests for backup / reject file clashes with symlinks