Dont use absolute pathname (dunno why i did that), fix tar filename/stdin problems

This commit is contained in:
Glenn L McGrath 2002-10-19 00:46:35 +00:00
parent 934805aec1
commit 98f824aa22

View File

@ -609,9 +609,9 @@ int tar_main(int argc, char **argv)
archive_handle_t *tar_handle; archive_handle_t *tar_handle;
int opt; int opt;
char *base_dir = NULL; char *base_dir = NULL;
char *tar_filename = "-";
#ifdef CONFIG_FEATURE_TAR_CREATE #ifdef CONFIG_FEATURE_TAR_CREATE
char *src_filename = NULL;
unsigned char tar_create = FALSE; unsigned char tar_create = FALSE;
#endif #endif
@ -629,7 +629,6 @@ int tar_main(int argc, char **argv)
/* Initialise default values */ /* Initialise default values */
tar_handle = init_handle(); tar_handle = init_handle();
tar_handle->src_fd = fileno(stdin);
tar_handle->flags = ARCHIVE_CREATE_LEADING_DIRS; tar_handle->flags = ARCHIVE_CREATE_LEADING_DIRS;
while ((opt = getopt(argc, argv, "ctxT:X:C:f:Opvz")) != -1) { while ((opt = getopt(argc, argv, "ctxT:X:C:f:Opvz")) != -1) {
@ -667,10 +666,7 @@ int tar_main(int argc, char **argv)
base_dir = optarg; base_dir = optarg;
break; break;
case 'f': /* archive filename */ case 'f': /* archive filename */
#ifdef CONFIG_FEATURE_TAR_CREATE tar_filename = optarg;
src_filename = optarg;
#endif
tar_handle->src_fd = xopen(optarg, O_RDONLY);
break; break;
case 'O': /* To stdout */ case 'O': /* To stdout */
tar_handle->action_data = data_extract_to_stdout; tar_handle->action_data = data_extract_to_stdout;
@ -711,16 +707,20 @@ int tar_main(int argc, char **argv)
/* Setup an array of filenames to work with */ /* Setup an array of filenames to work with */
/* TODO: This is the same as in ar, seperate function ? */ /* TODO: This is the same as in ar, seperate function ? */
while (optind < argc) { while (optind < argc) {
#if 0
char absolute_path[PATH_MAX]; char absolute_path[PATH_MAX];
realpath(argv[optind], absolute_path); realpath(argv[optind], absolute_path);
tar_handle->accept = add_to_list(tar_handle->accept, absolute_path); tar_handle->accept = add_to_list(tar_handle->accept, absolute_path);
#endif
tar_handle->accept = add_to_list(tar_handle->accept, argv[optind]);
optind++; optind++;
#ifdef CONFIG_FEATURE_TAR_EXCLUDE #ifdef CONFIG_FEATURE_TAR_EXCLUDE
if (tar_handle->reject) { if (tar_handle->reject) {
tar_handle->filter = filter_accept_reject_list; tar_handle->filter = filter_accept_reject_list;
} else } else
#endif #endif /* CONFIG_FEATURE_TAR_EXCLUDE */
tar_handle->filter = filter_accept_list; tar_handle->filter = filter_accept_list;
} }
@ -738,26 +738,35 @@ int tar_main(int argc, char **argv)
if (get_header_ptr == get_header_tar_gz) { if (get_header_ptr == get_header_tar_gz) {
gzipFlag = TRUE; gzipFlag = TRUE;
} }
# endif # endif /* CONFIG_FEATURE_TAR_GZIP */
if (tar_handle->action_header == header_verbose_list) { if (tar_handle->action_header == header_verbose_list) {
verboseFlag = TRUE; verboseFlag = TRUE;
} }
writeTarFile(src_filename, verboseFlag, tar_handle->accept, writeTarFile(tar_filename, verboseFlag, tar_handle->accept,
tar_handle->reject, gzipFlag); tar_handle->reject, gzipFlag);
} else } else
#endif #endif /* CONFIG_FEATURE_TAR_CREATE */
{
if ((tar_filename[0] == '-') && (tar_filename[1] == '\0')) {
tar_handle->src_fd = fileno(stdin);
} else {
tar_handle->src_fd = xopen(tar_filename, O_RDONLY);
}
#ifdef CONFIG_FEATURE_TAR_GZIP #ifdef CONFIG_FEATURE_TAR_GZIP
if (get_header_ptr == get_header_tar_gz) { if (get_header_ptr == get_header_tar_gz) {
get_header_tar_gz(tar_handle); get_header_tar_gz(tar_handle);
} else } else
#endif #endif /* CONFIG_FEATURE_TAR_CREATE */
while (get_header_tar(tar_handle) == EXIT_SUCCESS); while (get_header_tar(tar_handle) == EXIT_SUCCESS);
}
#ifdef CONFIG_FEATURE_CLEAN_UP #ifdef CONFIG_FEATURE_CLEAN_UP
if (tar_handle->src_fd != fileno(stdin)) { if (tar_handle->src_fd != fileno(stdin)) {
close(tar_handle->src_fd); close(tar_handle->src_fd);
} }
#endif #endif /* CONFIG_FEATURE_CLEAN_UP */
return(EXIT_SUCCESS); return(EXIT_SUCCESS);
} }