diff options
author | Matt Kraai <kraai@debian.org> | 2001-01-22 05:25:19 +0000 |
---|---|---|
committer | Matt Kraai <kraai@debian.org> | 2001-01-22 05:25:19 +0000 |
commit | 8f8dab94e579958e5702d535b7b023bb548f5b64 (patch) | |
tree | 2b38d31e022f2b0f9750608c0609d9fcb8039ba6 /archival | |
parent | 0d5a08ed923acc955cb832992d46225951cb73d2 (diff) | |
download | busybox-w32-8f8dab94e579958e5702d535b7b023bb548f5b64.tar.gz busybox-w32-8f8dab94e579958e5702d535b7b023bb548f5b64.tar.bz2 busybox-w32-8f8dab94e579958e5702d535b7b023bb548f5b64.zip |
Fixed listed files to extract to be more like GNU. Reported by Deon George.
Diffstat (limited to 'archival')
-rw-r--r-- | archival/tar.c | 52 |
1 files changed, 23 insertions, 29 deletions
diff --git a/archival/tar.c b/archival/tar.c index 49e99a1a5..bf8f9b813 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -604,6 +604,21 @@ int exclude_file(char **excluded_files, const char *file) | |||
604 | return 0; | 604 | return 0; |
605 | } | 605 | } |
606 | 606 | ||
607 | int extract_file(char **extract_files, const char *file) | ||
608 | { | ||
609 | int i; | ||
610 | |||
611 | if (extract_files == NULL) | ||
612 | return 1; | ||
613 | |||
614 | for (i = 0; extract_files[i] != NULL; i++) { | ||
615 | if (fnmatch(extract_files[i], file, FNM_LEADING_DIR) == 0) | ||
616 | return 1; | ||
617 | } | ||
618 | |||
619 | return 0; | ||
620 | } | ||
621 | |||
607 | /* | 622 | /* |
608 | * Read a tar file and extract or list the specified files within it. | 623 | * Read a tar file and extract or list the specified files within it. |
609 | * If the list is empty than all files are extracted or listed. | 624 | * If the list is empty than all files are extracted or listed. |
@@ -617,7 +632,6 @@ extern int readTarFile(int tarFd, int extractFlag, int listFlag, | |||
617 | int skipNextHeaderFlag=FALSE; | 632 | int skipNextHeaderFlag=FALSE; |
618 | TarHeader rawHeader; | 633 | TarHeader rawHeader; |
619 | TarInfo header; | 634 | TarInfo header; |
620 | char** tmpList; | ||
621 | 635 | ||
622 | /* Set the umask for this process so it doesn't | 636 | /* Set the umask for this process so it doesn't |
623 | * screw up permission setting for us later. */ | 637 | * screw up permission setting for us later. */ |
@@ -669,30 +683,16 @@ extern int readTarFile(int tarFd, int extractFlag, int listFlag, | |||
669 | } | 683 | } |
670 | #endif | 684 | #endif |
671 | 685 | ||
672 | if (extractList != NULL) { | 686 | if (!extract_file(extractList, header.name)) { |
673 | int skipFlag = TRUE; | ||
674 | for (tmpList = extractList; *tmpList != NULL; tmpList++) { | ||
675 | if (strncmp( *tmpList, header.name, strlen(*tmpList))==0 || ( | ||
676 | header.name[strlen(header.name)-1]=='/' | ||
677 | && strncmp( *tmpList, header.name, | ||
678 | MIN(strlen(header.name)-1, strlen(*tmpList)))==0)) { | ||
679 | /* If it is a regular file, pretend to extract it with | ||
680 | * the extractFlag set to FALSE, so the junk in the tarball | ||
681 | * is properly skipped over */ | ||
682 | skipFlag = FALSE; | ||
683 | memmove(extractList+1, extractList, | ||
684 | sizeof(*extractList)*(tmpList-extractList)); | ||
685 | extractList++; | ||
686 | break; | ||
687 | } | ||
688 | } | ||
689 | /* There are not the droids you're looking for, move along */ | 687 | /* There are not the droids you're looking for, move along */ |
690 | if (skipFlag == TRUE) { | 688 | /* If it is a regular file, pretend to extract it with |
691 | if ( header.type==REGTYPE || header.type==REGTYPE0 ) | 689 | * the extractFlag set to FALSE, so the junk in the tarball |
692 | if (tarExtractRegularFile(&header, FALSE, FALSE) == FALSE) | 690 | * is properly skipped over */ |
693 | errorFlag = TRUE; | 691 | if ( header.type==REGTYPE || header.type==REGTYPE0 ) { |
694 | continue; | 692 | if (tarExtractRegularFile(&header, FALSE, FALSE) == FALSE) |
693 | errorFlag = TRUE; | ||
695 | } | 694 | } |
695 | continue; | ||
696 | } | 696 | } |
697 | 697 | ||
698 | if (listFlag == TRUE) { | 698 | if (listFlag == TRUE) { |
@@ -813,12 +813,6 @@ extern int readTarFile(int tarFd, int extractFlag, int listFlag, | |||
813 | /* Stuff to do when we are done */ | 813 | /* Stuff to do when we are done */ |
814 | endgame: | 814 | endgame: |
815 | close( tarFd); | 815 | close( tarFd); |
816 | if (extractList != NULL) { | ||
817 | for (; *extractList != NULL; extractList++) { | ||
818 | error_msg("%s: Not found in archive\n", *extractList); | ||
819 | errorFlag = TRUE; | ||
820 | } | ||
821 | } | ||
822 | if ( *(header.name) == '\0' ) { | 816 | if ( *(header.name) == '\0' ) { |
823 | if (errorFlag==TRUE) | 817 | if (errorFlag==TRUE) |
824 | error_msg( "Error exit delayed from previous errors\n"); | 818 | error_msg( "Error exit delayed from previous errors\n"); |