* archival/bunzip2.c (bunzip2_main): Remove compressed file.
authorMatt Kraai <kraai@debian.org>
Wed, 27 Mar 2002 17:46:44 +0000 (17:46 -0000)
committerMatt Kraai <kraai@debian.org>
Wed, 27 Mar 2002 17:46:44 +0000 (17:46 -0000)
* testsuite/bunzip2/bunzip2-removes-compressed-file: New.

archival/bunzip2.c
testsuite/bunzip2/bunzip2-removes-compressed-file [new file with mode: 0644]

index 678779e64854af255518454b0de8c4a447847f2c..a7b41b7d1fdc7e29380c900c559dd8dec05858d8 100644 (file)
@@ -2323,10 +2323,12 @@ int bunzip2_main(int argc, char **argv)
        const int bunzip_force = 2;
        int flags = 0;
        int opt = 0;
+       int status;
 
        FILE *src_stream;
        FILE *dst_stream;
        char *save_name = NULL;
+       char *delete_name = NULL;
 
        /* if called as bzcat */
        if (strcmp(applet_name, "bzcat") == 0)
@@ -2369,7 +2371,22 @@ int bunzip2_main(int argc, char **argv)
        } else {
                dst_stream = xfopen(save_name, "w");
        }
-       uncompressStream(src_stream, dst_stream);
 
-       return(TRUE);
+       if (uncompressStream(src_stream, dst_stream)) {
+               if (save_name != NULL)
+                       delete_name = argv[optind];
+               status = EXIT_SUCCESS;
+       } else {
+               if (save_name != NULL)
+                       delete_name = save_name;
+               status = EXIT_FAILURE;
+       }
+
+       if (delete_name) {
+               if (unlink(delete_name) < 0) {
+                       error_msg_and_die("Couldn't remove %s", delete_name);
+               }
+       }
+
+       return status;
 }
diff --git a/testsuite/bunzip2/bunzip2-removes-compressed-file b/testsuite/bunzip2/bunzip2-removes-compressed-file
new file mode 100644 (file)
index 0000000..f1d1550
--- /dev/null
@@ -0,0 +1,3 @@
+echo foo | bzip2 >foo.bz2
+busybox bunzip2 foo.bz2
+test ! -f foo.bz2