bbunzip: fix comments to match reality

This commit is contained in:
Denis Vlasenko 2007-03-07 23:22:47 +00:00
parent 36b7e28fa0
commit 6c939e0cb4

View File

@ -42,14 +42,14 @@ int unpack(char **argv,
{ {
struct stat stat_buf; struct stat stat_buf;
USE_DESKTOP(long long) int status; USE_DESKTOP(long long) int status;
char *filename; char *filename, *new_name;
/* NB: new_name is *possibly* malloc'ed! */
smallint exitcode = 0; smallint exitcode = 0;
do { do {
char *new_name = NULL; /* NB: new_name is *maybe* malloc'ed! */
new_name = NULL;
filename = *argv; /* can be NULL - 'streaming' bunzip2 */ filename = *argv; /* can be NULL - 'streaming' bunzip2 */
if (filename && LONE_DASH(filename)) if (filename && LONE_DASH(filename))
filename = NULL; filename = NULL;
@ -73,22 +73,21 @@ int unpack(char **argv,
filename = NULL; filename = NULL;
} }
/* Open dst unless -c, "-" or called as bzcat */ /* Open dst if we are going to unpack to file */
if (filename) { if (filename) {
new_name = make_new_name(filename); new_name = make_new_name(filename);
if (!new_name) { if (!new_name) {
bb_error_msg("%s: unknown suffix - ignored", filename); bb_error_msg("%s: unknown suffix - ignored", filename);
goto err; goto err;
} }
/* O_EXCL: "real" bunzip2 doesn't overwrite files too */ /* O_EXCL: "real" bunzip2 doesn't overwrite files */
/* TODO: "real" gunzip goes not bail out, but goes /* GNU gunzip goes not bail out, but goes to next file */
* to next file */
if (open_to_or_warn(STDOUT_FILENO, new_name, O_WRONLY | O_CREAT | O_EXCL, if (open_to_or_warn(STDOUT_FILENO, new_name, O_WRONLY | O_CREAT | O_EXCL,
stat_buf.st_mode)) stat_buf.st_mode))
goto err; goto err;
} }
/* Check that the input is sane. */ /* Check that the input is sane */
if (isatty(STDIN_FILENO) && (option_mask32 & OPT_FORCE) == 0) { if (isatty(STDIN_FILENO) && (option_mask32 & OPT_FORCE) == 0) {
bb_error_msg_and_die("compressed data not read from terminal, " bb_error_msg_and_die("compressed data not read from terminal, "
"use -f to force it"); "use -f to force it");
@ -102,14 +101,15 @@ int unpack(char **argv,
char *del = new_name; char *del = new_name;
if (status >= 0) { if (status >= 0) {
/* TODO: restore user/group/times here? */ /* TODO: restore user/group/times here? */
/* delete _old_ file */ /* Delete _compressed_ file */
del = filename; del = filename;
/* Restore extension (unless tgz -> tar case) */ /* restore extension (unless tgz -> tar case) */
if (new_name == filename) if (new_name == filename)
filename[strlen(filename)] = '.'; filename[strlen(filename)] = '.';
} }
if (unlink(del) < 0) if (unlink(del) < 0)
bb_perror_msg_and_die("cannot remove %s", del); bb_perror_msg_and_die("cannot remove %s", del);
#if 0 /* Currently buggy - wrong name: "a.gz: 261% - replaced with a.gz" */ #if 0 /* Currently buggy - wrong name: "a.gz: 261% - replaced with a.gz" */
/* Extreme bloat for gunzip compat */ /* Extreme bloat for gunzip compat */
if (ENABLE_DESKTOP && (option_mask32 & OPT_VERBOSE) && status >= 0) { if (ENABLE_DESKTOP && (option_mask32 & OPT_VERBOSE) && status >= 0) {
@ -117,6 +117,7 @@ int unpack(char **argv,
filename, (unsigned)(stat_buf.st_size*100 / (status+1)), new_name); filename, (unsigned)(stat_buf.st_size*100 / (status+1)), new_name);
} }
#endif #endif
free_name: free_name:
if (new_name != filename) if (new_name != filename)
free(new_name); free(new_name);
@ -133,8 +134,8 @@ char* make_new_name_bunzip2(char *filename)
{ {
char *extension = strrchr(filename, '.'); char *extension = strrchr(filename, '.');
if (!extension || strcmp(extension, ".bz2") != 0) { if (!extension || strcmp(extension, ".bz2") != 0) {
/* Mimic GNU gunzip ("real" bunzip2 tries to */ /* Mimic GNU gunzip - "real" bunzip2 tries to */
/* unpack file anyway, to file.out) */ /* unpack file anyway, to file.out */
return NULL; return NULL;
} }
*extension = '\0'; *extension = '\0';