Patch from Matt Kraai:
The following patch makes the -X option to tar behave like GNU, which reads one file per line. It also prevents the last file from being appended to the list twice (though that has no noticeable impact).
This commit is contained in:
parent
bd193a42a5
commit
4836fd44f0
@ -246,7 +246,8 @@ extern int tar_main(int argc, char **argv)
|
|||||||
#if defined BB_FEATURE_TAR_EXCLUDE
|
#if defined BB_FEATURE_TAR_EXCLUDE
|
||||||
case 'e':
|
case 'e':
|
||||||
if (strcmp(*argv, "xclude")==0) {
|
if (strcmp(*argv, "xclude")==0) {
|
||||||
excludeList=xrealloc( excludeList, sizeof(char**) * (excludeListSize+2));
|
excludeList=xrealloc( excludeList,
|
||||||
|
sizeof(char *) * (excludeListSize+2));
|
||||||
excludeList[excludeListSize] = *(++argv);
|
excludeList[excludeListSize] = *(++argv);
|
||||||
if (excludeList[excludeListSize] == NULL)
|
if (excludeList[excludeListSize] == NULL)
|
||||||
error_msg_and_die( "Option requires an argument: No file specified\n");
|
error_msg_and_die( "Option requires an argument: No file specified\n");
|
||||||
@ -258,30 +259,30 @@ extern int tar_main(int argc, char **argv)
|
|||||||
stopIt=TRUE;
|
stopIt=TRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'X':
|
case 'X':
|
||||||
if (*excludeFileName != '-')
|
if (*excludeFileName != '-')
|
||||||
error_msg_and_die("Only one 'X' option allowed\n");
|
error_msg_and_die("Only one 'X' option allowed\n");
|
||||||
excludeFileName = *(++argv);
|
excludeFileName = *(++argv);
|
||||||
if (excludeFileName == NULL)
|
if (excludeFileName == NULL)
|
||||||
error_msg_and_die("Option requires an argument: No file specified\n");
|
error_msg_and_die("Option requires an argument: No file specified\n");
|
||||||
fileList = fopen (excludeFileName, "rt");
|
fileList = fopen (excludeFileName, "r");
|
||||||
if (! fileList)
|
if (! fileList)
|
||||||
error_msg_and_die("Exclude file: file not found\n");
|
error_msg_and_die("Exclude file: file not found\n");
|
||||||
while (!feof(fileList)) {
|
while (fgets(file, sizeof(file), fileList) != NULL) {
|
||||||
fscanf(fileList, "%s", file);
|
excludeList = xrealloc(excludeList,
|
||||||
excludeList=xrealloc( excludeList, sizeof(char**) * (excludeListSize+2));
|
sizeof(char *) * (excludeListSize+2));
|
||||||
excludeList[excludeListSize] = malloc(sizeof(char) * (strlen(file)+1));
|
if (file[strlen(file)-1] == '\n')
|
||||||
strcpy(excludeList[excludeListSize],file);
|
file[strlen(file)-1] = '\0';
|
||||||
/* Remove leading "/"s */
|
excludeList[excludeListSize] = xstrdup(file);
|
||||||
if (*excludeList[excludeListSize] == '/')
|
/* Remove leading "/"s */
|
||||||
excludeList[excludeListSize] = (excludeList[excludeListSize])+1;
|
while (*excludeList[excludeListSize] == '/')
|
||||||
/* Tack a NULL onto the end of the list */
|
excludeList[excludeListSize]++;
|
||||||
excludeList[++excludeListSize] = NULL;
|
/* Tack a NULL onto the end of the list */
|
||||||
}
|
excludeList[++excludeListSize] = NULL;
|
||||||
|
}
|
||||||
fclose(fileList);
|
fclose(fileList);
|
||||||
stopIt=TRUE;
|
stopIt=TRUE;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case '-':
|
case '-':
|
||||||
break;
|
break;
|
||||||
|
51
tar.c
51
tar.c
@ -246,7 +246,8 @@ extern int tar_main(int argc, char **argv)
|
|||||||
#if defined BB_FEATURE_TAR_EXCLUDE
|
#if defined BB_FEATURE_TAR_EXCLUDE
|
||||||
case 'e':
|
case 'e':
|
||||||
if (strcmp(*argv, "xclude")==0) {
|
if (strcmp(*argv, "xclude")==0) {
|
||||||
excludeList=xrealloc( excludeList, sizeof(char**) * (excludeListSize+2));
|
excludeList=xrealloc( excludeList,
|
||||||
|
sizeof(char *) * (excludeListSize+2));
|
||||||
excludeList[excludeListSize] = *(++argv);
|
excludeList[excludeListSize] = *(++argv);
|
||||||
if (excludeList[excludeListSize] == NULL)
|
if (excludeList[excludeListSize] == NULL)
|
||||||
error_msg_and_die( "Option requires an argument: No file specified\n");
|
error_msg_and_die( "Option requires an argument: No file specified\n");
|
||||||
@ -258,30 +259,30 @@ extern int tar_main(int argc, char **argv)
|
|||||||
stopIt=TRUE;
|
stopIt=TRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'X':
|
case 'X':
|
||||||
if (*excludeFileName != '-')
|
if (*excludeFileName != '-')
|
||||||
error_msg_and_die("Only one 'X' option allowed\n");
|
error_msg_and_die("Only one 'X' option allowed\n");
|
||||||
excludeFileName = *(++argv);
|
excludeFileName = *(++argv);
|
||||||
if (excludeFileName == NULL)
|
if (excludeFileName == NULL)
|
||||||
error_msg_and_die("Option requires an argument: No file specified\n");
|
error_msg_and_die("Option requires an argument: No file specified\n");
|
||||||
fileList = fopen (excludeFileName, "rt");
|
fileList = fopen (excludeFileName, "r");
|
||||||
if (! fileList)
|
if (! fileList)
|
||||||
error_msg_and_die("Exclude file: file not found\n");
|
error_msg_and_die("Exclude file: file not found\n");
|
||||||
while (!feof(fileList)) {
|
while (fgets(file, sizeof(file), fileList) != NULL) {
|
||||||
fscanf(fileList, "%s", file);
|
excludeList = xrealloc(excludeList,
|
||||||
excludeList=xrealloc( excludeList, sizeof(char**) * (excludeListSize+2));
|
sizeof(char *) * (excludeListSize+2));
|
||||||
excludeList[excludeListSize] = malloc(sizeof(char) * (strlen(file)+1));
|
if (file[strlen(file)-1] == '\n')
|
||||||
strcpy(excludeList[excludeListSize],file);
|
file[strlen(file)-1] = '\0';
|
||||||
/* Remove leading "/"s */
|
excludeList[excludeListSize] = xstrdup(file);
|
||||||
if (*excludeList[excludeListSize] == '/')
|
/* Remove leading "/"s */
|
||||||
excludeList[excludeListSize] = (excludeList[excludeListSize])+1;
|
while (*excludeList[excludeListSize] == '/')
|
||||||
/* Tack a NULL onto the end of the list */
|
excludeList[excludeListSize]++;
|
||||||
excludeList[++excludeListSize] = NULL;
|
/* Tack a NULL onto the end of the list */
|
||||||
}
|
excludeList[++excludeListSize] = NULL;
|
||||||
|
}
|
||||||
fclose(fileList);
|
fclose(fileList);
|
||||||
stopIt=TRUE;
|
stopIt=TRUE;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case '-':
|
case '-':
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user