864b1f
diff -up patch-2.7.1/src/patch.c.remove-empty-dir patch-2.7.1/src/patch.c
864b1f
--- patch-2.7.1/src/patch.c.remove-empty-dir	2012-10-18 17:57:41.708586721 +0100
864b1f
+++ patch-2.7.1/src/patch.c	2013-03-11 11:35:54.607901400 +0000
864b1f
@@ -646,8 +646,8 @@ main (int argc, char **argv)
864b1f
     if (outstate.ofp && (ferror (outstate.ofp) || fclose (outstate.ofp) != 0))
864b1f
       write_fatal ();
864b1f
     output_files (NULL);
864b1f
-    delete_files ();
864b1f
     cleanup ();
864b1f
+    delete_files ();
864b1f
     if (somefailed)
864b1f
       exit (1);
864b1f
     return 0;
864b1f
diff -up patch-2.7.1/tests/Makefile.am.remove-empty-dir patch-2.7.1/tests/Makefile.am
864b1f
--- patch-2.7.1/tests/Makefile.am.remove-empty-dir	2012-09-14 10:15:22.000000000 +0100
864b1f
+++ patch-2.7.1/tests/Makefile.am	2013-03-11 11:35:54.619901466 +0000
864b1f
@@ -49,6 +49,7 @@ TESTS = \
864b1f
 	reject-format \
864b1f
 	remember-backup-files \
864b1f
 	remember-reject-files \
864b1f
+	remove-directories \
864b1f
 	symlinks \
864b1f
 	unmodified-files
864b1f
 
864b1f
diff -up patch-2.7.1/tests/remove-directories.remove-empty-dir patch-2.7.1/tests/remove-directories
864b1f
--- patch-2.7.1/tests/remove-directories.remove-empty-dir	2013-03-11 11:35:54.619901466 +0000
864b1f
+++ patch-2.7.1/tests/remove-directories	2013-03-11 11:35:54.619901466 +0000
864b1f
@@ -0,0 +1,29 @@
864b1f
+# Copyright (C) 2013 Free Software Foundation, Inc.
864b1f
+#
864b1f
+# Copying and distribution of this file, with or without modification,
864b1f
+# in any medium, are permitted without royalty provided the copyright
864b1f
+# notice and this notice are preserved.
864b1f
+
864b1f
+. $srcdir/test-lib.sh
864b1f
+
864b1f
+require_cat
864b1f
+use_local_patch
864b1f
+use_tmpdir
864b1f
+
864b1f
+# ==============================================================
864b1f
+# Remove empty parent diectories when removing a file
864b1f
+
864b1f
+mkdir dir
864b1f
+echo foobar > dir/file
864b1f
+cat > apatch <
864b1f
+--- dir/file
864b1f
++++ /dev/null
864b1f
+@@ -1 +0,0 @@
864b1f
+-foobar
864b1f
+EOF
864b1f
+
864b1f
+check 'patch -p0 -E < apatch' <
864b1f
+patching file dir/file
864b1f
+EOF
864b1f
+
864b1f
+ncheck '! test -e dir'