[BusyBox] error in the tar patch

Sebastien Cote scote1 at Matrox.COM
Wed Aug 23 18:22:53 UTC 2000


Hi,

I forgot to take out #if defined BB_FEATURE_TAR_INCLUDE from the patch I
sent
yesterday.  I added this for debugging purposes and removed every other
occurences
except for this one.

The included patch fixes this.  I used the patched tar a lot today and
everything
works fine (except for the command line parsing bug I reported
yesterday).


-- 
Sébastien Côté
-------------- next part --------------
--- tar.orig.c	Thu Jul  6 18:29:44 2000
+++ tar.c	Tue Aug 22 13:28:27 2000
@@ -75,6 +75,8 @@
 	"\tO\t\textract to stdout\n"
 #if defined BB_FEATURE_TAR_EXCLUDE
 	"\t--exclude\tfile to exclude\n"
+   "\t--exclude-from=\texclude files from file\n"
+   "\t--files-from=\tinclude files from file\n"
 #endif
 	"\nInformative output:\n"
 	"\tv\t\tverbosely list files processed\n"
@@ -163,16 +165,20 @@
 #ifdef BB_FEATURE_TAR_CREATE
 /* Local procedures to save files into a tar file.  */
 static int writeTarFile(const char* tarName, int tostdoutFlag, 
-		int verboseFlag, int argc, char **argv, char** excludeList);
+		int verboseFlag, int argc, char **argv, char** excludeList, char** includeList);
 #endif
 
 
 extern int tar_main(int argc, char **argv)
 {
 	char** excludeList=NULL;
+	char** includeList=NULL;
 #if defined BB_FEATURE_TAR_EXCLUDE
 	int excludeListSize=0;
 #endif
+	int includeListSize=0;
 	const char *tarName="-";
 	int listFlag     = FALSE;
 	int extractFlag  = FALSE;
@@ -247,7 +253,87 @@
 						stopIt=TRUE;
 						break;
 					}
+
+					else if (strncmp(*argv, "-exclude-from=", 14)==0) {
+						FILE *fileList;
+						char file[256];
+						int i;
+
+						if (strlen(*argv) == 14) {
+							fatalError( "Option requires an argument: No file specified\n");
+						}
+						fileList = fopen (*(argv)+14, "rt");
+						if (!fileList) {
+							fatalError( "--exclude-from: file not found\n");
+						}
+
+						while (!feof(fileList)) {
+							fscanf(fileList, "%s", file);
+							if (excludeList == NULL || strcmp(file, excludeList[excludeListSize-1])) {
+								
+								excludeList=realloc( excludeList, sizeof(char**) * (excludeListSize+2));
+								excludeList[excludeListSize] = malloc(sizeof(char) * (strlen(file)+1));
+								strcpy(excludeList[excludeListSize], file);
+								
+								if (excludeList[excludeListSize++] == NULL)
+									fatalError( "Option requires an argument: No file specified\n");
+								/* Tack a NULL onto the end of the list */
+								excludeList[excludeListSize] = NULL;
+							}
+						}
+
+						/* Remove leading "/"s */
+						for (i=0; i < excludeListSize; i++) {
+							if (*excludeList[i] =='/') {
+								excludeList[i] = (excludeList[i])+1;
+							}
+						}
+						
+						fclose(fileList);
+						stopIt=TRUE;
+						break;
+					}
 #endif
+					if (strncmp(*argv, "-files-from=", 12)==0) {
+						FILE *fileList;
+						char file[256];
+						int i;
+						
+						if (strlen(*argv) == 12) {
+							fatalError( "Option requires an argument: No file specified\n");
+						}
+						
+						fileList = fopen (*(argv)+12, "rt");
+						if (!fileList) {
+							fatalError( "--files-from: file not found\n");
+						}
+						while (!feof(fileList)) {
+							fscanf(fileList, "%s", file);
+							if (includeList == NULL || strcmp(file, includeList[includeListSize-1])) {
+								
+								includeList=realloc( includeList, sizeof(char**) * (includeListSize+2));
+								includeList[includeListSize] = malloc(sizeof(char) * (strlen(file)+1));
+								strcpy(includeList[includeListSize], file);
+								
+								if (includeList[includeListSize++] == NULL)
+									fatalError( "Option requires an argument: No file specified\n");
+								/* Tack a NULL onto the end of the list */
+								includeList[includeListSize] = NULL;
+							}
+						}
+
+						/* Remove leading "/"s */
+						for (i=0; i < includeListSize; i++) {
+							if (*includeList[i] =='/') {
+								includeList[i] = (includeList[i])+1;
+							}
+						}
+						
+						fclose(fileList);
+						stopIt=TRUE;
+						break;
+					}
+					
 					if (strcmp(*argv, "-help")==0) {
 						usage(tar_usage);
 					}
@@ -269,7 +355,7 @@
 #ifndef BB_FEATURE_TAR_CREATE
 		fatalError( "This version of tar was not compiled with tar creation support.\n");
 #else
-		exit(writeTarFile(tarName, tostdoutFlag, verboseFlag, argc, argv, excludeList));
+		exit(writeTarFile(tarName, tostdoutFlag, verboseFlag, argc, argv, excludeList, includeList));
 #endif
 	}
 	if (listFlag == TRUE || extractFlag == TRUE) {
@@ -945,16 +1031,17 @@
 }
 
 static int writeTarFile(const char* tarName, int tostdoutFlag, 
-		int verboseFlag, int argc, char **argv, char** excludeList)
+		int verboseFlag, int argc, char **argv, char** excludeList, char** includeList)
 {
 	int tarFd=-1;
+	int i=0;
 	int errorFlag=FALSE;
 	ssize_t size;
 	struct TarBallInfo tbInfo;
 	tbInfo.verboseFlag = verboseFlag;
 
 	/* Make sure there is at least one file to tar up.  */
-	if (argc <= 0)
+	if (argc <= 0 && !includeList)
 		fatalError("tar: Cowardly refusing to create an empty archive\n");
 
 	/* Open the tar file for writing.  */
@@ -984,6 +1071,17 @@
 			errorFlag = TRUE;
 		}
 	}
+	if (includeList)
+	{
+		while (includeList[i])
+		{
+			if (recursiveAction(includeList[i++], TRUE, FALSE, FALSE,
+				writeFileToTarball, writeFileToTarball, 
+				(void*) &tbInfo) == FALSE) {
+				errorFlag = TRUE;
+			}
+		}
+	}
 	/* Write two empty blocks to the end of the archive */
 	for (size=0; size<(2*TAR_BLOCK_SIZE); size++) {
 		write(tbInfo.tarFd, "\0", 1);
@@ -996,6 +1094,19 @@
 
 	/* Hang up the tools, close up shop, head home */
 	close(tarFd);
+	
+	if (includeList) {
+		i=0;
+		while (includeList[i])
+			free(includeList[i++]);
+		free(includeList);
+	}
+	if (excludeList) {
+		i=0;
+		while (excludeList[i])
+			free(excludeList[i++]);
+		free(excludeList);
+	}
 	if (errorFlag == TRUE) {
 		errorMsg("tar: Error exit delayed from previous errors\n");
 		return(FALSE);


More information about the busybox mailing list