You removed the functionality of my filterfunc here. It was ment to prevent unpacking files which might overwrite something. It shouldn't happen with the current DD code, so I think we should be good here. But it might be a good idea to delete the agrument from the header too.. -- Martin SivÃk msivak@xxxxxxxxxx Red Hat Czech Anaconda team / Brno, CZ ----- "David Cantrell" <dcantrell@xxxxxxxxxx> wrote: > Simplify the archive extraction loop in explodeRPM() by using the > unpack.c helper functions. Add a new parameter to explodeRPM, the > destination to unpack the archive to. This was previously handled > by dlabelUnpackRPMDir() directly, but it made more sense to me to > move it in to the libarchive unpack helper. > --- > loader/driverdisk.c | 24 +----------- > loader/rpmextract.c | 106 > ++++----------------------------------------------- > loader/rpmextract.h | 3 +- > 3 files changed, 11 insertions(+), 122 deletions(-) > > diff --git a/loader/driverdisk.c b/loader/driverdisk.c > index 9b4c710..c56f3e5 100644 > --- a/loader/driverdisk.c > +++ b/loader/driverdisk.c > @@ -145,24 +145,9 @@ int globErrFunc(const char *epath, int eerrno) > > int dlabelUnpackRPMDir(char* rpmdir, char* destination, char > *kernelver) > { > - char *oldcwd; > char *globpattern; > int rc = 0; > > - /* get current working directory */ > - oldcwd = getcwd(NULL, 0); > - if (!oldcwd) { > - logMessage(ERROR, "getcwd() failed: %m"); > - return 1; > - } > - > - /* set the cwd to destination */ > - if (chdir(destination)) { > - logMessage(ERROR, "We weren't able to CWD to \"%s\": %m", > destination); > - free(oldcwd); > - return 1; > - } > - > checked_asprintf(&globpattern, "%s/*.rpm", rpmdir); > glob_t globres; > char** globitem; > @@ -170,7 +155,7 @@ int dlabelUnpackRPMDir(char* rpmdir, char* > destination, char *kernelver) > /* iterate over all rpm files */ > globitem = globres.gl_pathv; > while (globres.gl_pathc>0 && globitem != NULL && *globitem != > NULL) { > - explodeRPM(*globitem, dlabelFilter, dlabelProvides, NULL, > kernelver); > + explodeRPM(*globitem, dlabelFilter, dlabelProvides, NULL, > kernelver, destination); > globitem++; > } > globfree(&globres); > @@ -178,13 +163,6 @@ int dlabelUnpackRPMDir(char* rpmdir, char* > destination, char *kernelver) > } > free(globpattern); > > - /* restore CWD */ > - if (chdir(oldcwd)) { > - logMessage(WARNING, "We weren't able to restore CWD to > \"%s\": %m", oldcwd); > - } > - > - /* cleanup */ > - free(oldcwd); > return rc; > } > > diff --git a/loader/rpmextract.c b/loader/rpmextract.c > index de803b8..3c8f564 100644 > --- a/loader/rpmextract.c > +++ b/loader/rpmextract.c > @@ -38,6 +38,7 @@ > > #include "loader.h" > #include "rpmextract.h" > +#include "unpack.h" > > #include "../pyanaconda/isys/log.h" > > @@ -93,7 +94,8 @@ int explodeRPM(const char *source, > filterfunc filter, > dependencyfunc provides, > dependencyfunc deps, > - void* userptr) > + void* userptr, > + char *destination) > { > char buffer[BUFFERSIZE+1]; /* make space for trailing \0 */ > FD_t fdi; > @@ -102,7 +104,6 @@ int explodeRPM(const char *source, > rpmRC rc; > FD_t gzdi; > struct archive *cpio; > - struct archive_entry *cpio_entry; > struct cpio_mydata cpio_mydata; > > rpmts ts; > @@ -235,17 +236,15 @@ int explodeRPM(const char *source, > return EXIT_FAILURE; > } > > + cpio_mydata.gzdi = gzdi; > + cpio_mydata.buffer = buffer; > + > /* initialize cpio decompressor */ > - cpio = archive_read_new(); > - if (cpio==NULL) { > + if (unpack_init(&cpio) != ARCHIVE_OK) { > Fclose(gzdi); > return -1; > } > > - cpio_mydata.gzdi = gzdi; > - cpio_mydata.buffer = buffer; > - archive_read_support_compression_all(cpio); > - archive_read_support_format_all(cpio); > rc = archive_read_open(cpio, &cpio_mydata, NULL, rpm_myread, > rpm_myclose); > > /* check the status of archive_open */ > @@ -255,96 +254,7 @@ int explodeRPM(const char *source, > } > > /* read all files in cpio archive */ > - while ((rc = archive_read_next_header(cpio, &cpio_entry)) == > ARCHIVE_OK){ > - const struct stat *fstat; > - int64_t fsize; > - const char* filename; > - int needskip = 1; /* do we need to read the data to get to > the next header? */ > - int offset = 0; > - int towrite = 0; > - > - filename = archive_entry_pathname(cpio_entry); > - fstat = archive_entry_stat(cpio_entry); > - fsize = archive_entry_size(cpio_entry); > - > - /* Strip leading slashes */ > - while (filename[offset] == '/') > - offset+=1; > - > - /* Strip leading ./ */ > - while (filename[offset] == '.' && filename[offset+1] == '/') > - offset+=2; > - > - /* Other file type - we do not care except special cases */ > - if (!S_ISREG(fstat->st_mode)) > - towrite = 1; > - else > - towrite = 2; > - > - if (filter && filter(filename+offset, fstat, userptr)) { > - /* filter this file */ > - towrite = 0; > - } > - > - /* Create directories */ > - char* dirname = strdup(filename+offset); > - > - /* If the dup fails, let's hope the dirs already exist */ > - if (dirname){ > - char* dirptr = dirname; > - while (dirptr && *dirptr) { > - dirptr = strchr(dirptr, '/'); > - if (dirptr) { > - *dirptr = 0; > - mkdir(dirname, 0700); > - *dirptr = '/'; > - dirptr++; > - } > - } > - free(dirname); > - } > - > - /* Regular file */ > - if (towrite>=2) { > - FILE *fdout = fopen(filename+offset, "w"); > - > - if (fdout==NULL){ > - rc = 33; > - break; > - } > - > - rc = archive_read_data_into_fd(cpio, fileno(fdout)); > - if (rc!=ARCHIVE_OK) { > - /* XXX We didn't get the file.. well.. */ > - needskip = 0; > - } else { > - needskip = 0; > - } > - > - fclose(fdout); > - } > - > - /* symlink, we assume that the path contained in symlink > - * is shorter than BUFFERSIZE */ > - while (towrite && S_ISLNK(fstat->st_mode)) { > - char symlinkbuffer[BUFFERSIZE-1]; > - > - needskip = 0; > - if ((rc = archive_read_data(cpio, symlinkbuffer, > fsize))!=ARCHIVE_OK) { > - /* XXX We didn't get the file.. well.. */ > - break; > - } > - > - if (symlink(buffer, filename+offset)) { > - logMessage(ERROR, "Failed to create symlink %s -> > %s", filename+offset, buffer); > - } > - > - break; > - } > - > - if(needskip) > - archive_read_data_skip(cpio); > - } > + unpack_members(cpio, destination); > > rc = archive_read_finish(cpio); /* Also closes the RPM stream > using callback */ > > diff --git a/loader/rpmextract.h b/loader/rpmextract.h > index 20a5cc8..976047c 100644 > --- a/loader/rpmextract.h > +++ b/loader/rpmextract.h > @@ -38,7 +38,8 @@ int explodeRPM(const char* file, > filterfunc filter, > dependencyfunc provides, > dependencyfunc deps, > - void* userptr); > + void* userptr, > + char *destination); > > #endif > > -- > 1.7.2.3 > > _______________________________________________ > Anaconda-devel-list mailing list > Anaconda-devel-list@xxxxxxxxxx > https://www.redhat.com/mailman/listinfo/anaconda-devel-list _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list