Match subdirectories of included/excluded files
This commit is contained in:
parent
527880e5cf
commit
d642a67928
@ -501,7 +501,19 @@ static int writeTarFile(const char* tarName, int verboseFlag, char **argv,
|
|||||||
}
|
}
|
||||||
#endif //tar_create
|
#endif //tar_create
|
||||||
|
|
||||||
void append_file_to_list(char *filename, char ***name_list, int *num_of_entries)
|
void append_file_to_list(const char *new_name, char ***list, int *list_count)
|
||||||
|
{
|
||||||
|
*list = realloc(*list, sizeof(char *) * (*list_count + 2));
|
||||||
|
if (last_char_is(new_name, '/')) {
|
||||||
|
(*list)[*list_count] = concat_path_file(new_name, "*");
|
||||||
|
} else {
|
||||||
|
(*list)[*list_count] = xstrdup(new_name);
|
||||||
|
}
|
||||||
|
(*list_count)++;
|
||||||
|
(*list)[*list_count] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void append_file_list_to_list(char *filename, char ***name_list, int *num_of_entries)
|
||||||
{
|
{
|
||||||
FILE *src_stream;
|
FILE *src_stream;
|
||||||
char *line;
|
char *line;
|
||||||
@ -513,13 +525,10 @@ void append_file_to_list(char *filename, char ***name_list, int *num_of_entries)
|
|||||||
if (line_ptr) {
|
if (line_ptr) {
|
||||||
*line_ptr = '\0';
|
*line_ptr = '\0';
|
||||||
}
|
}
|
||||||
*name_list = realloc(*name_list, sizeof(char *) * (*num_of_entries + 2));
|
append_file_to_list(line, name_list, num_of_entries);
|
||||||
(*name_list)[*num_of_entries] = xstrdup(line);
|
|
||||||
(*num_of_entries)++;
|
|
||||||
free(line);
|
free(line);
|
||||||
}
|
}
|
||||||
fclose(src_stream);
|
fclose(src_stream);
|
||||||
(*name_list)[*num_of_entries] = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BB_FEATURE_TAR_EXCLUDE
|
#ifdef BB_FEATURE_TAR_EXCLUDE
|
||||||
@ -627,13 +636,12 @@ int tar_main(int argc, char **argv)
|
|||||||
/* Exclude or Include files listed in <filename>*/
|
/* Exclude or Include files listed in <filename>*/
|
||||||
#ifdef BB_FEATURE_TAR_EXCLUDE
|
#ifdef BB_FEATURE_TAR_EXCLUDE
|
||||||
case 'X':
|
case 'X':
|
||||||
append_file_to_list(optarg, &exclude_list, &exclude_list_count);
|
append_file_list_to_list(optarg, &exclude_list, &exclude_list_count);
|
||||||
exclude_list[exclude_list_count] = NULL;
|
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case 'T':
|
case 'T':
|
||||||
// by default a list is an include list
|
// by default a list is an include list
|
||||||
append_file_to_list(optarg, &include_list, &include_list_count);
|
append_file_list_to_list(optarg, &include_list, &include_list_count);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'C': // Change to dir <optarg>
|
case 'C': // Change to dir <optarg>
|
||||||
@ -683,11 +691,8 @@ int tar_main(int argc, char **argv)
|
|||||||
|
|
||||||
/* Setup an array of filenames to work with */
|
/* Setup an array of filenames to work with */
|
||||||
while (optind < argc) {
|
while (optind < argc) {
|
||||||
include_list = realloc(include_list, sizeof(char *) * (include_list_count + 2));
|
append_file_to_list(argv[optind], &include_list, &include_list_count);
|
||||||
include_list[include_list_count] = xstrdup(argv[optind]);
|
|
||||||
include_list_count++;
|
|
||||||
optind++;
|
optind++;
|
||||||
include_list[include_list_count] = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* By default the include list is the list we act on */
|
/* By default the include list is the list we act on */
|
||||||
|
29
tar.c
29
tar.c
@ -501,7 +501,19 @@ static int writeTarFile(const char* tarName, int verboseFlag, char **argv,
|
|||||||
}
|
}
|
||||||
#endif //tar_create
|
#endif //tar_create
|
||||||
|
|
||||||
void append_file_to_list(char *filename, char ***name_list, int *num_of_entries)
|
void append_file_to_list(const char *new_name, char ***list, int *list_count)
|
||||||
|
{
|
||||||
|
*list = realloc(*list, sizeof(char *) * (*list_count + 2));
|
||||||
|
if (last_char_is(new_name, '/')) {
|
||||||
|
(*list)[*list_count] = concat_path_file(new_name, "*");
|
||||||
|
} else {
|
||||||
|
(*list)[*list_count] = xstrdup(new_name);
|
||||||
|
}
|
||||||
|
(*list_count)++;
|
||||||
|
(*list)[*list_count] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void append_file_list_to_list(char *filename, char ***name_list, int *num_of_entries)
|
||||||
{
|
{
|
||||||
FILE *src_stream;
|
FILE *src_stream;
|
||||||
char *line;
|
char *line;
|
||||||
@ -513,13 +525,10 @@ void append_file_to_list(char *filename, char ***name_list, int *num_of_entries)
|
|||||||
if (line_ptr) {
|
if (line_ptr) {
|
||||||
*line_ptr = '\0';
|
*line_ptr = '\0';
|
||||||
}
|
}
|
||||||
*name_list = realloc(*name_list, sizeof(char *) * (*num_of_entries + 2));
|
append_file_to_list(line, name_list, num_of_entries);
|
||||||
(*name_list)[*num_of_entries] = xstrdup(line);
|
|
||||||
(*num_of_entries)++;
|
|
||||||
free(line);
|
free(line);
|
||||||
}
|
}
|
||||||
fclose(src_stream);
|
fclose(src_stream);
|
||||||
(*name_list)[*num_of_entries] = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BB_FEATURE_TAR_EXCLUDE
|
#ifdef BB_FEATURE_TAR_EXCLUDE
|
||||||
@ -627,13 +636,12 @@ int tar_main(int argc, char **argv)
|
|||||||
/* Exclude or Include files listed in <filename>*/
|
/* Exclude or Include files listed in <filename>*/
|
||||||
#ifdef BB_FEATURE_TAR_EXCLUDE
|
#ifdef BB_FEATURE_TAR_EXCLUDE
|
||||||
case 'X':
|
case 'X':
|
||||||
append_file_to_list(optarg, &exclude_list, &exclude_list_count);
|
append_file_list_to_list(optarg, &exclude_list, &exclude_list_count);
|
||||||
exclude_list[exclude_list_count] = NULL;
|
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case 'T':
|
case 'T':
|
||||||
// by default a list is an include list
|
// by default a list is an include list
|
||||||
append_file_to_list(optarg, &include_list, &include_list_count);
|
append_file_list_to_list(optarg, &include_list, &include_list_count);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'C': // Change to dir <optarg>
|
case 'C': // Change to dir <optarg>
|
||||||
@ -683,11 +691,8 @@ int tar_main(int argc, char **argv)
|
|||||||
|
|
||||||
/* Setup an array of filenames to work with */
|
/* Setup an array of filenames to work with */
|
||||||
while (optind < argc) {
|
while (optind < argc) {
|
||||||
include_list = realloc(include_list, sizeof(char *) * (include_list_count + 2));
|
append_file_to_list(argv[optind], &include_list, &include_list_count);
|
||||||
include_list[include_list_count] = xstrdup(argv[optind]);
|
|
||||||
include_list_count++;
|
|
||||||
optind++;
|
optind++;
|
||||||
include_list[include_list_count] = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* By default the include list is the list we act on */
|
/* By default the include list is the list we act on */
|
||||||
|
Loading…
Reference in New Issue
Block a user