summaryrefslogtreecommitdiffhomepage
path: root/archival
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2000-09-09 14:50:04 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2000-09-09 14:50:04 +0000
commite2b345a6d8269048e2a310de70234b28745c42c1 (patch)
tree405335677a6dde5f184d81e000ef7a4eb0c90770 /archival
parent437bf72785cdd8c9d689c241a94c79f1f71a2354 (diff)
Implemented new ar functionality unique to busybox ar (i think), the -R
option enable a Recursive extraction (or listing) to take place. i.e. if any files being extracted are themselves ar archives then busybox ar will extract their contents as well. e.g. take bar.deb and do (with GNU ar) ar -q foo.deb b.ar then with busybox ar can do ar -x b.ar data.tar.gz -R isnt used for anything in GNU ar so i think it should be ok, could have used long options This functionality will become (more) usufull with tar, gz support.
Diffstat (limited to 'archival')
-rw-r--r--archival/ar.c34
1 files changed, 15 insertions, 19 deletions
diff --git a/archival/ar.c b/archival/ar.c
index 41750ac7c..5803ad1a7 100644
--- a/archival/ar.c
+++ b/archival/ar.c
@@ -43,6 +43,7 @@
#define DISPLAY 4 /* display contents */
#define EXT_TO_FILE 8 /* extract contents of archive */
#define EXT_TO_STDOUT 16 /* extract to stdout */
+#define RECURSIVE 32
#define MAX_NAME_LENGTH 100
@@ -168,34 +169,26 @@ static int readArEntry(int srcFd, headerL_t *newEntry)
/*
* return the headerL_t struct for the specified filename
*/
-static headerL_t *getHeaders(int srcFd, headerL_t *head)
+static headerL_t *getHeaders(int srcFd, headerL_t *head, int funct)
{
- int arEntry=FALSE;
headerL_t *list;
list = (headerL_t *) malloc(sizeof(headerL_t));
- if (checkArMagic(srcFd)==TRUE)
- arEntry=TRUE;
- else
- errorMsg("isnt an ar archive\n");
-
- if (arEntry==TRUE) {
+ if (checkArMagic(srcFd)==TRUE) {
+ printf("found ar header ");
while(readArEntry(srcFd, list) == TRUE) {
list->next = (headerL_t *) malloc(sizeof(headerL_t));
*list->next = *head;
*head = *list;
-
+
/* recursive check for sub-archives */
- lseek(srcFd, list->size, SEEK_CUR);
-/* printf("checking for sub headers\n");
- if ((subList = getHeaders(srcFd, list->next)) != NULL) {
- printf("found a sub archive !\n");
- }
- else
- printf("didnt find a sub header\n"); */
+ if ((funct & RECURSIVE) == RECURSIVE)
+ head = getHeaders(srcFd, head, funct);
+ lseek(srcFd, head->offset + head->size, SEEK_SET);
}
}
-
+ else
+ printf("not an ar header\n");
return(head);
}
@@ -239,7 +232,7 @@ extern int ar_main(int argc, char **argv)
int srcFd=0, dstFd=0;
headerL_t *header, *entry, *extractList;
- while ((opt = getopt(argc, argv, "ovtpx")) != -1) {
+ while ((opt = getopt(argc, argv, "ovtpxR")) != -1) {
switch (opt) {
case 'o':
funct = funct | PRESERVE_DATE;
@@ -256,6 +249,9 @@ extern int ar_main(int argc, char **argv)
case 'p':
funct = funct | EXT_TO_STDOUT;
break;
+ case 'R':
+ funct = funct | RECURSIVE;
+ break;
default:
usage(ar_usage);
}
@@ -276,7 +272,7 @@ extern int ar_main(int argc, char **argv)
header = (headerL_t *) malloc(sizeof(headerL_t));
extractList = (headerL_t *) malloc(sizeof(headerL_t));
- header = getHeaders(srcFd, header);
+ header = getHeaders(srcFd, header, funct);
/* find files to extract or display */
if (optind<argc) {