mirror of
https://github.com/sheumann/hush.git
synced 2024-12-22 14:30:31 +00:00
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.
This commit is contained in:
parent
437bf72785
commit
e2b345a6d8
32
ar.c
32
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");
|
||||
if ((funct & RECURSIVE) == RECURSIVE)
|
||||
head = getHeaders(srcFd, head, funct);
|
||||
lseek(srcFd, head->offset + head->size, SEEK_SET);
|
||||
}
|
||||
}
|
||||
else
|
||||
printf("didnt find a sub header\n"); */
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -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");
|
||||
if ((funct & RECURSIVE) == RECURSIVE)
|
||||
head = getHeaders(srcFd, head, funct);
|
||||
lseek(srcFd, head->offset + head->size, SEEK_SET);
|
||||
}
|
||||
}
|
||||
else
|
||||
printf("didnt find a sub header\n"); */
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user