[BusyBox] Fix for busybox-tar

Matt Kraai kraai at alumni.carnegiemellon.edu
Mon Dec 18 04:37:09 UTC 2000


On Sun, Dec 17, 2000 at 11:11:17PM +0100, Arne Bernin wrote:
> attached are two patches to cleanup the tar.c (two lines ;-), 
> and get archiving the root dir (/) right.
> 
> The first one is only to get the same behaviour for --exclude and -X, as -X
> strips off all leading '/'s, and --exclude does this only whith the first. i
> do not know if this is the right thing, there are still some Problems with
> making things like tar -cv --exclude /init.d -f /tmp/test.tar /etc, as this
> excludes /etc/init.d which it should not in my opinion.

How about the following patch?  It strips off the leading /'s of
excluded files as well as moving the code which decides whether or
not to write the file to the tarball into writeFileToTarball so
that it doesn't need to use weird hacks.  Unfortunately,
recursive_action still recurses on excluded directories, leading
to errors.  But this is a start.

Matt
-------------- next part --------------
Index: tar.c
===================================================================
RCS file: /var/cvs/busybox/tar.c,v
retrieving revision 1.82
diff -u -r1.82 tar.c
--- tar.c	2000/12/18 03:57:16	1.82
+++ tar.c	2000/12/18 04:34:41
@@ -252,8 +252,8 @@
 						if (excludeList[excludeListSize] == NULL)
 							error_msg_and_die( "Option requires an argument: No file specified\n");
 						/* Remove leading "/"s */
-						if (*excludeList[excludeListSize] =='/')
-							excludeList[excludeListSize] = (excludeList[excludeListSize])+1;
+						while (*excludeList[excludeListSize] =='/')
+							excludeList[excludeListSize]++;
 						/* Tack a NULL onto the end of the list */
 						excludeList[++excludeListSize] = NULL;
 						stopIt=TRUE;
@@ -940,43 +940,12 @@
 {
 	long chksum=0;
 	struct TarHeader header;
-#if defined BB_FEATURE_TAR_EXCLUDE
-	char** tmpList;
-#endif
 	const unsigned char *cp = (const unsigned char *) &header;
 	ssize_t size = sizeof(struct TarHeader);
 		
 	memset( &header, 0, size);
 
-	if (*fileName=='/') {
-		static int alreadyWarned=FALSE;
-		if (alreadyWarned==FALSE) {
-			error_msg("Removing leading '/' from member names\n");
-			alreadyWarned=TRUE;
-		}
-		strncpy(header.name, fileName+1, sizeof(header.name)); 
-	}
-	else {
-		strncpy(header.name, fileName, sizeof(header.name)); 
-	}
-
-#if defined BB_FEATURE_TAR_EXCLUDE
-	/* Check for excluded files....  */
-	for (tmpList=tbInfo->excludeList; tmpList && *tmpList; tmpList++) {
-		/* Do some extra hoop jumping for when directory names
-		 * end in '/' but the entry in tmpList doesn't */
-		if (strncmp( *tmpList, header.name, strlen(*tmpList))==0 || (
-					header.name[strlen(header.name)-1]=='/'
-					&& strncmp( *tmpList, header.name, 
-						MIN(strlen(header.name)-1, strlen(*tmpList)))==0)) {
-			/* Set the mode to something that is not a regular file, thereby
-			 * faking out writeTarFile into thinking that nothing further need
-			 * be done for this file.  Yes, I know this is ugly, but it works. */
-			statbuf->st_mode = 0;
-			return( TRUE);
-		}
-	}
-#endif
+	strncpy(header.name, fileName, sizeof(header.name)); 
 
 	putOctal(header.mode, sizeof(header.mode), statbuf->st_mode);
 	putOctal(header.uid, sizeof(header.uid), statbuf->st_uid);
@@ -1065,6 +1034,9 @@
 static int writeFileToTarball(const char *fileName, struct stat *statbuf, void* userData)
 {
 	struct TarBallInfo *tbInfo = (struct TarBallInfo *)userData;
+#if defined BB_FEATURE_TAR_EXCLUDE
+	char** tmpList;
+#endif
 
 	/*
 	** Check to see if we are dealing with a hard link.
@@ -1097,10 +1069,36 @@
 		return( TRUE);
 	}
 
+	while (fileName[0] == '/') {
+		static int alreadyWarned=FALSE;
+		if (alreadyWarned==FALSE) {
+			error_msg("Removing leading '/' from member names\n");
+			alreadyWarned=TRUE;
+		}
+		fileName++;
+	}
+
 	if (strlen(fileName) >= NAME_SIZE) {
 		error_msg(name_longer_than_foo, NAME_SIZE);
 		return ( TRUE);
 	}
+
+	if (fileName[0] == '\0')
+		return TRUE;
+
+#if defined BB_FEATURE_TAR_EXCLUDE
+	/* Check for excluded files....  */
+	for (tmpList=tbInfo->excludeList; tmpList && *tmpList; tmpList++) {
+		/* Do some extra hoop jumping for when directory names
+		 * end in '/' but the entry in tmpList doesn't */
+		if (strncmp( *tmpList, fileName, strlen(*tmpList))==0 || (
+					fileName[strlen(fileName)-1]=='/'
+					&& strncmp( *tmpList, fileName, 
+						MIN(strlen(fileName)-1, strlen(*tmpList)))==0)) {
+			return TRUE;
+		}
+	}
+#endif
 
 	if (writeTarHeader(tbInfo, fileName, statbuf)==FALSE) {
 		return( FALSE);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/busybox/attachments/20001217/7dcf2aa3/attachment.pgp 


More information about the busybox mailing list