File quilt-setup-06-check-for-directories-too.patch of Package quilt

Check for existing directories before unpacking.
---
 quilt/setup.in  |   22 ++++++++++++++++++++++
 test/setup.test |    7 ++++++-
 2 files changed, 28 insertions(+), 1 deletion(-)

--- a/quilt/setup.in
+++ b/quilt/setup.in
@@ -22,6 +22,25 @@ then
 	fi
 fi
 
+check_for_existing_directories() {
+	local tag dir last_dir arg status=0
+
+	while read tag dir arg
+	do
+		[ "$dir" != "." -a "$dir" != "$last_dir" ] || continue
+
+		if [ -e "$prefix$dir" ]
+		then
+			printf $"Directory %s exists\n" \
+			       "$prefix$dir" >&2
+			status=1
+		fi
+		last_dir=$dir
+	done < $tmpfile
+
+	return $status
+}
+
 check_for_existing_files() {
 	local tag dir last_dir arg status=0
 
@@ -196,6 +215,9 @@ case "$1" in
 	;;
 esac
 
+# Make sure that unpacking will not overwrite anything
+check_for_existing_directories || exit 1
+
 while read tag dir arg1 arg2
 do
 	case "$tag" in
--- a/test/setup.test
+++ b/test/setup.test
@@ -64,12 +64,17 @@ $ quilt push -qa
 $ cd ../..
 $ rm -rf "dir"
 
-# Now test the case where the tarball contains a patches directory
+# Now test the cases where the directory already exists, or the tarball
+# contains a patches directory
 $ cat > series_with_patches
 < # Source: dir_with_patches.tar.gz
 < # Patchdir: dir
 < #
 < foo.diff
+$ mkdir dir
+$ quilt setup series_with_patches
+> Directory dir exists
+$ rmdir dir
 $ quilt setup series_with_patches
 > Unpacking archive dir_with_patches.tar.gz
 > Directory dir/patches exists
openSUSE Build Service is sponsored by