diff options
author | Matt Kraai <kraai@debian.org> | 2002-03-27 17:46:44 +0000 |
---|---|---|
committer | Matt Kraai <kraai@debian.org> | 2002-03-27 17:46:44 +0000 |
commit | cf32ac543c618dec10a01a14744cee6e306d430e (patch) | |
tree | 4f91dbf1dbce9140ecf4504f2005be1101a6d811 | |
parent | 35d60421b4f61de9f5ed39c3057555e6f64d75a7 (diff) | |
download | busybox-w32-cf32ac543c618dec10a01a14744cee6e306d430e.tar.gz busybox-w32-cf32ac543c618dec10a01a14744cee6e306d430e.tar.bz2 busybox-w32-cf32ac543c618dec10a01a14744cee6e306d430e.zip |
* archival/bunzip2.c (bunzip2_main): Remove compressed file.
* testsuite/bunzip2/bunzip2-removes-compressed-file: New.
-rw-r--r-- | archival/bunzip2.c | 21 | ||||
-rw-r--r-- | testsuite/bunzip2/bunzip2-removes-compressed-file | 3 |
2 files changed, 22 insertions, 2 deletions
diff --git a/archival/bunzip2.c b/archival/bunzip2.c index 678779e64..a7b41b7d1 100644 --- a/archival/bunzip2.c +++ b/archival/bunzip2.c | |||
@@ -2323,10 +2323,12 @@ int bunzip2_main(int argc, char **argv) | |||
2323 | const int bunzip_force = 2; | 2323 | const int bunzip_force = 2; |
2324 | int flags = 0; | 2324 | int flags = 0; |
2325 | int opt = 0; | 2325 | int opt = 0; |
2326 | int status; | ||
2326 | 2327 | ||
2327 | FILE *src_stream; | 2328 | FILE *src_stream; |
2328 | FILE *dst_stream; | 2329 | FILE *dst_stream; |
2329 | char *save_name = NULL; | 2330 | char *save_name = NULL; |
2331 | char *delete_name = NULL; | ||
2330 | 2332 | ||
2331 | /* if called as bzcat */ | 2333 | /* if called as bzcat */ |
2332 | if (strcmp(applet_name, "bzcat") == 0) | 2334 | if (strcmp(applet_name, "bzcat") == 0) |
@@ -2369,7 +2371,22 @@ int bunzip2_main(int argc, char **argv) | |||
2369 | } else { | 2371 | } else { |
2370 | dst_stream = xfopen(save_name, "w"); | 2372 | dst_stream = xfopen(save_name, "w"); |
2371 | } | 2373 | } |
2372 | uncompressStream(src_stream, dst_stream); | ||
2373 | 2374 | ||
2374 | return(TRUE); | 2375 | if (uncompressStream(src_stream, dst_stream)) { |
2376 | if (save_name != NULL) | ||
2377 | delete_name = argv[optind]; | ||
2378 | status = EXIT_SUCCESS; | ||
2379 | } else { | ||
2380 | if (save_name != NULL) | ||
2381 | delete_name = save_name; | ||
2382 | status = EXIT_FAILURE; | ||
2383 | } | ||
2384 | |||
2385 | if (delete_name) { | ||
2386 | if (unlink(delete_name) < 0) { | ||
2387 | error_msg_and_die("Couldn't remove %s", delete_name); | ||
2388 | } | ||
2389 | } | ||
2390 | |||
2391 | return status; | ||
2375 | } | 2392 | } |
diff --git a/testsuite/bunzip2/bunzip2-removes-compressed-file b/testsuite/bunzip2/bunzip2-removes-compressed-file new file mode 100644 index 000000000..f1d15503e --- /dev/null +++ b/testsuite/bunzip2/bunzip2-removes-compressed-file | |||
@@ -0,0 +1,3 @@ | |||
1 | echo foo | bzip2 >foo.bz2 | ||
2 | busybox bunzip2 foo.bz2 | ||
3 | test ! -f foo.bz2 | ||