diff options
author | jbj <devnull@localhost> | 2001-01-25 20:26:35 +0000 |
---|---|---|
committer | jbj <devnull@localhost> | 2001-01-25 20:26:35 +0000 |
commit | dd94329f0c3d6fc592a88c68d7df833f88435f09 (patch) | |
tree | 389a78a852e7e7d5a45522b1c2c8cb2ccd6d77d4 /lib | |
parent | 5ae2e10e9eaef7c0ca0104c0294f16eb66c9958e (diff) | |
download | librpm-tizen-dd94329f0c3d6fc592a88c68d7df833f88435f09.tar.gz librpm-tizen-dd94329f0c3d6fc592a88c68d7df833f88435f09.tar.bz2 librpm-tizen-dd94329f0c3d6fc592a88c68d7df833f88435f09.zip |
- remove support for v1 src rpm's.
- reposition callbacks with ts/fi in cpio payload layer.
CVS patchset: 4498
CVS date: 2001/01/25 20:26:35
Diffstat (limited to 'lib')
-rw-r--r-- | lib/cpio.c | 280 | ||||
-rw-r--r-- | lib/cpio.h | 39 | ||||
-rw-r--r-- | lib/install.c | 186 | ||||
-rw-r--r-- | lib/install.h | 2 | ||||
-rw-r--r-- | lib/rollback.h | 1 | ||||
-rw-r--r-- | lib/rpmlib.h | 3 |
6 files changed, 213 insertions, 298 deletions
diff --git a/lib/cpio.c b/lib/cpio.c index 77764153b..afc0132b1 100644 --- a/lib/cpio.c +++ b/lib/cpio.c @@ -83,7 +83,9 @@ struct cpioCrcPhysicalHeader { * File name and stat information. */ struct cpioHeader { - /*@owned@*/ const char * path; +/*@owned@*/ const char * path; + FD_t cfd; + void * mapi; struct stat sb; }; @@ -149,6 +151,7 @@ static const char * mapMd5sum(const void * this) { /** */ struct mapi { + rpmTransactionSet ts; TFI_t fi; int i; struct cpioFileMapping map; @@ -171,21 +174,48 @@ static void mapFree(const void * this) { /** */ -static void mapFreeIterator(/*@only@*/ const void * this) { - if (this) - free((void *)this); +static void mapFreeIterator(/*@only@*/ const void * this) +{ + struct mapi * mapi; + rpmTransactionSet ts; + TFI_t fi; + + if (this == NULL) + return; + + mapi = (void *)this; + ts = mapi->ts; + fi = mapi->fi; + + if (ts && ts->notify) { + unsigned int archiveSize = (fi->archiveSize ? fi->archiveSize : 100); + (void)ts->notify(fi->h, RPMCALLBACK_INST_PROGRESS, + archiveSize, archiveSize, + (fi->ap ? fi->ap->key : NULL), ts->notifyData); + } + free((void *)this); } /** */ -static void * mapInitIterator(const void * this) { +static void * mapInitIterator(const void * this, const void * that) +{ struct mapi * mapi; + rpmTransactionSet ts = (void *)this; + TFI_t fi = (void *)that; - if (this == NULL) + if (fi == NULL) return NULL; mapi = xcalloc(sizeof(*mapi), 1); - mapi->fi = (void *)this; + mapi->ts = ts; + mapi->fi = fi; mapi->i = 0; + + if (ts && ts->notify) { + (void)ts->notify(fi->h, RPMCALLBACK_INST_START, 0, fi->archiveSize, + (fi->ap ? fi->ap->key : NULL), ts->notifyData); + } + return mapi; } @@ -248,6 +278,25 @@ static const void * mapFind(void * this, const char * hdrPath) { } /** + */ +static void hdrCallback(const struct cpioHeader * hdr) +{ + struct mapi * mapi = hdr->mapi; + rpmTransactionSet ts; + TFI_t fi; + + if (mapi == NULL) + return; + ts = mapi->ts; + fi = mapi->fi; + + if (ts && ts->notify) + (void)ts->notify(fi->h, RPMCALLBACK_INST_PROGRESS, + fdGetCpioPos(hdr->cfd), fi->archiveSize, + (fi->ap ? fi->ap->key : NULL), ts->notifyData); +} + +/** * Read data from payload. * @param cfd payload file handle * @retval vbuf data from read @@ -391,12 +440,11 @@ static int strntoul(const char *str, /*@out@*/char **endptr, int base, int num) /** * Process next cpio heasder. - * @param cfd payload file handle * @retval hdr file name and stat info * @return 0 on success */ -static int getNextHeader(FD_t cfd, struct cpioHeader * hdr) - /*@modifies cfd, hdr->path, hdr->sb @*/ +static int getNextHeader(struct cpioHeader * hdr) + /*@modifies hdr->cfd, hdr->path, hdr->sb @*/ { struct cpioCrcPhysicalHeader physHeader; struct stat * st = &hdr->sb; @@ -404,7 +452,7 @@ static int getNextHeader(FD_t cfd, struct cpioHeader * hdr) char * end; int major, minor; - if (ourread(cfd, &physHeader, PHYS_HDR_SIZE) != PHYS_HDR_SIZE) + if (ourread(hdr->cfd, &physHeader, PHYS_HDR_SIZE) != PHYS_HDR_SIZE) return CPIOERR_READ_FAILED; if (strncmp(CPIO_CRC_MAGIC, physHeader.magic, sizeof(CPIO_CRC_MAGIC)-1) && @@ -430,7 +478,7 @@ static int getNextHeader(FD_t cfd, struct cpioHeader * hdr) GET_NUM_FIELD(physHeader.namesize, nameSize); { char * t = xmalloc(nameSize + 1); - if (ourread(cfd, t, nameSize) != nameSize) { + if (ourread(hdr->cfd, t, nameSize) != nameSize) { free(t); hdr->path = NULL; return CPIOERR_BAD_HEADER; @@ -440,7 +488,7 @@ static int getNextHeader(FD_t cfd, struct cpioHeader * hdr) /* this is unecessary hdr->path[nameSize] = '\0'; */ - padinfd(cfd, 4); + padinfd(hdr->cfd, 4); return 0; } @@ -476,7 +524,7 @@ static int createDirectory(const char * path, mode_t perms) if (mkdir(path, 000)) return CPIOERR_MKDIR_FAILED; - if (chmod(path, perms)) + if (perms != 000 && chmod(path, perms)) return CPIOERR_CHMOD_FAILED; return 0; @@ -487,12 +535,12 @@ static int createDirectory(const char * path, mode_t perms) * @param hdr file name and stat info * @return 0 on success */ -static int setInfo(struct cpioHeader * hdr) +static int setInfo(const struct cpioHeader * hdr) /*@modifies fileSystem @*/ { int rc = 0; struct utimbuf stamp; - struct stat * st = &hdr->sb; + const struct stat * st = &hdr->sb; stamp.actime = st->st_mtime; stamp.modtime = st->st_mtime; @@ -570,13 +618,10 @@ static int inline checkDirectory(const char * filename) /*@*/ * @param cfd payload file handle * @param hdr file name and stat info * @param filemd5 file md5 sum - * @param cb callback function - * @param cbData callback private data * @return 0 on success */ -static int expandRegular(FD_t cfd, const struct cpioHeader * hdr, - const char * filemd5, cpioCallback cb, void * cbData) - /*@modifies fileSystem, cfd @*/ +static int expandRegular(const struct cpioHeader * hdr, const char * filemd5) + /*@modifies fileSystem, hdr->cfd @*/ { FD_t ofd; char buf[BUFSIZ]; @@ -584,7 +629,6 @@ static int expandRegular(FD_t cfd, const struct cpioHeader * hdr, const struct stat * st = &hdr->sb; int left = st->st_size; int rc = 0; - struct cpioCallbackInfo cbInfo = { NULL, 0, 0, 0 }; struct stat sb; /* Rename the old file before attempting unlink to avoid EBUSY errors */ @@ -614,11 +658,8 @@ static int expandRegular(FD_t cfd, const struct cpioHeader * hdr, if (filemd5) fdInitMD5(ofd, 0); - cbInfo.file = hdr->path; - cbInfo.fileSize = st->st_size; - while (left) { - bytesRead = ourread(cfd, buf, left < sizeof(buf) ? left : sizeof(buf)); + bytesRead = ourread(hdr->cfd, buf, left < sizeof(buf) ? left : sizeof(buf)); if (bytesRead <= 0) { rc = CPIOERR_READ_FAILED; break; @@ -632,11 +673,8 @@ static int expandRegular(FD_t cfd, const struct cpioHeader * hdr, left -= bytesRead; /* don't call this with fileSize == fileComplete */ - if (!rc && cb && left) { - cbInfo.fileComplete = st->st_size - left; - cbInfo.bytesProcessed = fdGetCpioPos(cfd); - cb(&cbInfo, cbData); - } + if (!rc && left) + hdrCallback(hdr); } if (filemd5) { @@ -661,12 +699,11 @@ static int expandRegular(FD_t cfd, const struct cpioHeader * hdr, /** * Create symlink from payload stream. - * @param cfd payload file handle * @param hdr file name and stat info * @return 0 on success */ -static int expandSymlink(FD_t cfd, const struct cpioHeader * hdr) - /*@modifies fileSystem, cfd @*/ +static int expandSymlink(const struct cpioHeader * hdr) + /*@modifies fileSystem, hdr->cfd @*/ { char buf[2048], buf2[2048]; struct stat sb; @@ -676,7 +713,7 @@ static int expandSymlink(FD_t cfd, const struct cpioHeader * hdr) if ((st->st_size + 1)> sizeof(buf)) return CPIOERR_HDR_SIZE; - if (ourread(cfd, buf, st->st_size) != st->st_size) + if (ourread(hdr->cfd, buf, st->st_size) != st->st_size) return CPIOERR_READ_FAILED; buf[st->st_size] = '\0'; @@ -706,7 +743,7 @@ static int expandSymlink(FD_t cfd, const struct cpioHeader * hdr) * @param hdr file name and stat info * @return 0 on success */ -static int expandFifo( /*@unused@*/ FD_t cfd, const struct cpioHeader * hdr) +static int expandFifo(const struct cpioHeader * hdr) /*@modifies fileSystem @*/ { struct stat sb; @@ -730,7 +767,7 @@ static int expandFifo( /*@unused@*/ FD_t cfd, const struct cpioHeader * hdr) * @param hdr file name and stat info * @return 0 on success */ -static int expandDevice( /*@unused@*/ FD_t cfd, const struct cpioHeader * hdr) +static int expandDevice(const struct cpioHeader * hdr) /*@modifies fileSystem @*/ { const struct stat * st = &hdr->sb; @@ -872,13 +909,11 @@ static int eatBytes(FD_t cfd, int amount) } /** @todo Verify payload MD5 sum. */ -int cpioInstallArchive(FD_t cfd, const TFI_t fi, cpioCallback cb, void * cbData, - const char ** failedFile) +int cpioInstallArchive(const rpmTransactionSet ts, const TFI_t fi, FD_t cfd, + const char ** failedFile) { struct cpioHeader ch, *hdr = &ch; - void * mapi = mapInitIterator(fi); const void * map = NULL; - struct cpioCallbackInfo cbInfo = { NULL, 0, 0, 0 }; struct hardLink * links = NULL; struct hardLink * li = NULL; int rc = 0; @@ -889,12 +924,14 @@ int cpioInstallArchive(FD_t cfd, const TFI_t fi, cpioCallback cb, void * cbData, fdInitMD5(cfd, 0); #endif - fdSetCpioPos(cfd, 0); + memset(hdr, 0, sizeof(*hdr)); + hdr->path = NULL; + hdr->mapi = mapInitIterator(ts, fi); + hdr->cfd = fdLink(cfd, "persist (cpioInstallArchive"); + fdSetCpioPos(hdr->cfd, 0); if (failedFile) *failedFile = NULL; - memset(hdr, 0, sizeof(*hdr)); - hdr->path = NULL; do { struct stat * st; @@ -902,7 +939,7 @@ int cpioInstallArchive(FD_t cfd, const TFI_t fi, cpioCallback cb, void * cbData, free((void *)hdr->path); hdr->path = NULL; } - if ((rc = getNextHeader(cfd, hdr))) { + if ((rc = getNextHeader(hdr))) { #if 0 /* XXX this is the failure point for an unreadable rpm */ rpmError(RPMERR_BADPACKAGE, _("getNextHeader: %s\n"), cpioStrerror(rc)); @@ -914,11 +951,11 @@ int cpioInstallArchive(FD_t cfd, const TFI_t fi, cpioCallback cb, void * cbData, if (!strcmp(hdr->path, TRAILER)) break; - if (mapi) - map = mapFind(mapi, hdr->path); + if (hdr->mapi) + map = mapFind(hdr->mapi, hdr->path); - if (mapi && map == NULL) { - eatBytes(cfd, st->st_size); + if (hdr->mapi && map == NULL) { + eatBytes(hdr->cfd, st->st_size); } else { if (map) { if (mapFlags(map, CPIO_MAP_PATH)) { @@ -934,9 +971,10 @@ int cpioInstallArchive(FD_t cfd, const TFI_t fi, cpioCallback cb, void * cbData, st->st_gid = mapFinalGid(map); } - /* This won't get hard linked symlinks right, but I can't seem - to create those anyway */ - + /* + * This won't get hard linked symlinks right, but I can't seem + * to create those anyway. + */ if (S_ISREG(st->st_mode) && st->st_nlink > 1) { for (li = links; li; li = li->next) { if (li->inode == st->st_ino && li->dev == st->st_dev) break; @@ -949,39 +987,38 @@ int cpioInstallArchive(FD_t cfd, const TFI_t fi, cpioCallback cb, void * cbData, } li->files[li->linksLeft++] = xstrdup(hdr->path); - } - if ((st->st_nlink > 1) && S_ISREG(st->st_mode) && !st->st_size && - li->createdPath == -1) { - /* defer file creation */ - } else if ((st->st_nlink > 1) && S_ISREG(st->st_mode) && - (li->createdPath != -1)) { - createLinks(li, failedFile); - - /* this only happens for cpio archives which contain - hardlinks w/ the contents of each hardlink being - listed (intead of the data being given just once. This - shouldn't happen, but I've made it happen w/ buggy - code, so what the heck? GNU cpio handles this well fwiw */ - if (st->st_size) eatBytes(cfd, st->st_size); + /* XXX FIXME 0 length hard linked files are broke. */ + if (st->st_size && li->createdPath == -1) { + createLinks(li, failedFile); + + /* + * This only happens for cpio archives which contain + * hardlinks w/ the contents of each hardlink being + * listed (intead of the data being given just once. This + * shouldn't happen, but I've made it happen w/ buggy + * code, so what the heck? GNU cpio handles this well fwiw. + */ + eatBytes(hdr->cfd, st->st_size); + } + } else { rc = checkDirectory(hdr->path); if (!rc) { if (S_ISREG(st->st_mode)) - rc = expandRegular(cfd, hdr, mapMd5sum(map), - cb, cbData); + rc = expandRegular(hdr, mapMd5sum(map)); else if (S_ISDIR(st->st_mode)) rc = createDirectory(hdr->path, 000); else if (S_ISLNK(st->st_mode)) - rc = expandSymlink(cfd, hdr); + rc = expandSymlink(hdr); else if (S_ISFIFO(st->st_mode)) - rc = expandFifo(cfd, hdr); + rc = expandFifo(hdr); else if (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode)) - rc = expandDevice(cfd, hdr); + rc = expandDevice(hdr); else if (S_ISSOCK(st->st_mode)) { - /* this mimicks cpio but probably isnt' right */ - rc = expandFifo(cfd, hdr); + /* this mimics cpio but probably isnt' right */ + rc = expandFifo(hdr); } else { rc = CPIOERR_UNKNOWN_FILETYPE; } @@ -1006,15 +1043,10 @@ int cpioInstallArchive(FD_t cfd, const TFI_t fi, cpioCallback cb, void * cbData, } } - padinfd(cfd, 4); + padinfd(hdr->cfd, 4); - if (!rc && cb) { - cbInfo.file = hdr->path; - cbInfo.fileSize = st->st_size; - cbInfo.fileComplete = st->st_size; - cbInfo.bytesProcessed = fdGetCpioPos(cfd); - cb(&cbInfo, cbData); - } + if (!rc) + hdrCallback(hdr); } while (rc == 0); @@ -1039,7 +1071,7 @@ int cpioInstallArchive(FD_t cfd, const TFI_t fi, cpioCallback cb, void * cbData, } #ifdef NOTYET - fdFiniMD5(cfd, (void **)&md5sum, NULL, 1); + fdFiniMD5(hdr->cfd, (void **)&md5sum, NULL, 1); if (md5sum) free(md5sum); @@ -1047,13 +1079,17 @@ int cpioInstallArchive(FD_t cfd, const TFI_t fi, cpioCallback cb, void * cbData, rc = 0; exit: - if (mapi) - mapFreeIterator(mapi); + fdFree(hdr->cfd, "persist (cpioInstallArchive"); + hdr->cfd = NULL; + if (hdr->mapi) + mapFreeIterator(hdr->mapi); return rc; } /** * Write next item to payload stream. + * @param ts transaction set + * @param fi transaction element file info * @param cfd payload file handle * @param st stat info for item * @param map mapping name and flags for item @@ -1061,8 +1097,8 @@ exit: * @param writeData should data be written? * @return 0 on success */ -static int writeFile(FD_t cfd, const struct stat * st, - const void * map, /*@out@*/ size_t * sizep, +static int writeFile(const rpmTransactionSet ts, TFI_t fi, FD_t cfd, + const struct stat * st, const void * map, /*@out@*/ size_t * sizep, int writeData) /*@modifies cfd, *sizep @*/ { @@ -1205,6 +1241,12 @@ static int writeFile(FD_t cfd, const struct stat * st, if (sizep) *sizep = size; + + if (ts && fi && ts->notify) { + (void)ts->notify(fi->h, RPMCALLBACK_INST_PROGRESS, size, size, + (fi->ap ? fi->ap->key : NULL), ts->notifyData); + } + rc = 0; exit: @@ -1214,21 +1256,19 @@ exit: /** * Write set of linked files to payload stream. + * @param ts transaction set + * @param fi transaction element file info * @param cfd payload file handle * @param hlink set of linked files - * @param cb callback function - * @param cbData callback private data * @retval sizep address of no. bytes written * @retval failedFile on error, file name that failed * @return 0 on success */ -static int writeLinkedFile(FD_t cfd, const struct hardLink * hlink, - cpioCallback cb, void * cbData, - /*@out@*/size_t * sizep, - /*@out@*/const char ** failedFile) +static int writeLinkedFile(const rpmTransactionSet ts, TFI_t fi, FD_t cfd, + const struct hardLink * hlink, /*@out@*/size_t * sizep, + /*@out@*/const char ** failedFile) /*@modifies cfd, *sizep, *failedFile @*/ { - struct cpioCallbackInfo cbInfo = { NULL, 0, 0, 0 }; const void * map = NULL; size_t total = 0; size_t size; @@ -1237,7 +1277,7 @@ static int writeLinkedFile(FD_t cfd, const struct hardLink * hlink, for (i = hlink->nlink - 1; i > hlink->linksLeft; i--) { map = hlink->fileMaps[i]; - if ((rc = writeFile(cfd, &hlink->sb, map, &size, 0)) != 0) { + if ((rc = writeFile(ts, fi, cfd, &hlink->sb, map, &size, 0)) != 0) { if (failedFile) *failedFile = mapFsPath(map); goto exit; @@ -1245,17 +1285,12 @@ static int writeLinkedFile(FD_t cfd, const struct hardLink * hlink, total += size; - if (cb) { - cbInfo.file = mapArchivePath(map); - cb(&cbInfo, cbData); - free((void *)cbInfo.file); - } mapFree(map); map = NULL; } i = hlink->linksLeft; map = hlink->fileMaps[i]; - if ((rc = writeFile(cfd, &hlink->sb, map, &size, 1))) { + if ((rc = writeFile(ts, fi, cfd, &hlink->sb, map, &size, 1))) { if (sizep) *sizep = total; if (failedFile) @@ -1267,11 +1302,6 @@ static int writeLinkedFile(FD_t cfd, const struct hardLink * hlink, if (sizep) *sizep = total; - if (cb) { - cbInfo.file = mapArchivePath(map); - cb(&cbInfo, cbData); - free((void *)cbInfo.file); - } rc = 0; exit: @@ -1280,13 +1310,11 @@ exit: return rc; } -int cpioBuildArchive(FD_t cfd, const TFI_t fi, cpioCallback cb, void * cbData, - unsigned int * archiveSize, const char ** failedFile) +int cpioBuildArchive(const rpmTransactionSet ts, const TFI_t fi, FD_t cfd, + unsigned int * archiveSize, const char ** failedFile) { - void * mapi = mapInitIterator(fi); + void * mapi = mapInitIterator(ts, fi); const void * map; - struct cpioCallbackInfo cbInfo = { NULL, 0, 0, 0 }; - struct cpioCrcPhysicalHeader hdr; /*@-fullinitblock@*/ struct hardLink hlinkList = { NULL }; /*@=fullinitblock@*/ @@ -1329,7 +1357,7 @@ int cpioBuildArchive(FD_t cfd, const TFI_t fi, cpioCallback cb, void * cbData, if (hlink->linksLeft == 0) { struct hardLink * prev; - rc = writeLinkedFile(cfd, hlink, cb, cbData, &size, failedFile); + rc = writeLinkedFile(ts, fi, cfd, hlink, &size, failedFile); if (rc) { free((void *)fsPath); return rc; @@ -1349,18 +1377,12 @@ int cpioBuildArchive(FD_t cfd, const TFI_t fi, cpioCallback cb, void * cbData, } while ((prev = prev->next) != NULL); } } else { - if ((rc = writeFile(cfd, st, map, &size, 1))) { + if ((rc = writeFile(ts, fi, cfd, st, map, &size, 1))) { if (failedFile) *failedFile = fsPath; return rc; } - if (cb) { - cbInfo.file = mapArchivePath(map); - cb(&cbInfo, cbData); - free((void *)cbInfo.file); - } - totalsize += size; } free((void *)fsPath); @@ -1374,7 +1396,7 @@ int cpioBuildArchive(FD_t cfd, const TFI_t fi, cpioCallback cb, void * cbData, hlink->next = NULL; if (rc == 0) { - rc = writeLinkedFile(cfd, hlink, cb, cbData, &size, failedFile); + rc = writeLinkedFile(ts, fi, cfd, hlink, &size, failedFile); totalsize += size; } freeHardLink(hlink); @@ -1382,15 +1404,17 @@ int cpioBuildArchive(FD_t cfd, const TFI_t fi, cpioCallback cb, void * cbData, if (rc) return rc; - memset(&hdr, '0', PHYS_HDR_SIZE); - memcpy(hdr.magic, CPIO_NEWC_MAGIC, sizeof(hdr.magic)); - memcpy(hdr.nlink, "00000001", 8); - memcpy(hdr.namesize, "0000000b", 8); - if ((rc = safewrite(cfd, &hdr, PHYS_HDR_SIZE)) != PHYS_HDR_SIZE) - return rc; - if ((rc = safewrite(cfd, "TRAILER!!!", 11)) != 11) - return rc; - totalsize += PHYS_HDR_SIZE + 11; + { struct cpioCrcPhysicalHeader hdr; + memset(&hdr, '0', PHYS_HDR_SIZE); + memcpy(hdr.magic, CPIO_NEWC_MAGIC, sizeof(hdr.magic)); + memcpy(hdr.nlink, "00000001", 8); + memcpy(hdr.namesize, "0000000b", 8); + if ((rc = safewrite(cfd, &hdr, PHYS_HDR_SIZE)) != PHYS_HDR_SIZE) + return rc; + if ((rc = safewrite(cfd, "TRAILER!!!", 11)) != 11) + return rc; + totalsize += PHYS_HDR_SIZE + 11; + } /* GNU cpio pads to 512 bytes here, but we don't. I'm not sure if it matters or not */ diff --git a/lib/cpio.h b/lib/cpio.h index ed87a60d6..910033202 100644 --- a/lib/cpio.h +++ b/lib/cpio.h @@ -67,10 +67,10 @@ typedef enum cpioMapFlags_e { * @note When building the cpio payload, only "file" is filled in. */ struct cpioCallbackInfo { -/*@dependent@*/ const char * file; /*!< File name being installed. */ - long fileSize; /*!< Total file size. */ - long fileComplete; /*!< Amount of file unpacked. */ - long bytesProcessed; /*!< No. bytes in archive read. */ +/*@owned@*/ const char * file; /*!< File name being installed. */ + long fileSize; /*!< Total file size. */ + long fileComplete; /*!< Amount of file unpacked. */ + long bytesProcessed; /*!< No. bytes in archive read. */ }; #ifdef __cplusplus @@ -85,36 +85,33 @@ typedef void (*cpioCallback) (struct cpioCallbackInfo * filespec, void * data); * The RPM internal equivalent of the command line "cpio -i". * * If no mappings are passed, this installs everything! If one is passed - * it should be sorted according to cpioFileMapCmp() and only files included - * in the map are installed. Files are installed relative to the current - * directory unless a mapping is given which specifies an absolute - * directory. The mode mapping is only used for the permission bits, not - * for the file type. The owner/group mappings are ignored for the nonroot - * user. + * it should be sorted, and only files included in the map are installed. + * Files are installed relative to the current directory unless a mapping + * is given which specifies an absolute directory. The mode mapping is only + * used for the permission bits, not for the file type. The owner/group + * mappings are ignored for the non-root user. * - * @param cfd file handle + * @param ts transaction set * @param fi transaction element file info - * @param cb progress callback - * @param cbData progress callback data - * @retval failedFile file name (malloc'ed) that caused failure (if any) + * @param cfd file handle + * @retval failedFile (malloc'd) file name that caused failure (if any) * @return 0 on success */ -int cpioInstallArchive(FD_t cfd, const TFI_t fi, cpioCallback cb, void * cbData, +int cpioInstallArchive(const rpmTransactionSet ts, const TFI_t fi, FD_t cfd, /*@out@*/const char ** failedFile) /*@modifies fileSystem, cfd, *failedFile @*/; /** \ingroup payload * The RPM internal equivalent of the command line "cpio -o". * - * @param cfd file handle + * @param ts transaction set * @param fi transaction element file info - * @param cb progress callback - * @param cbData progress callback data - * @retval failedFile file name (malloc'ed) that caused failure (if any) + * @param cfd file handle + * @retval failedFile (malloc'd) file name that caused failure (if any) * @return 0 on success */ -int cpioBuildArchive(FD_t cfd, const TFI_t fi, cpioCallback cb, void * cbData, - unsigned int * archiveSize, /*@out@*/const char ** failedFile) +int cpioBuildArchive(const rpmTransactionSet ts, const TFI_t fi, FD_t cfd, + unsigned int * archiveSize, /*@out@*/ const char ** failedFile) /*@modifies fileSystem, cfd, *archiveSize, *failedFile @*/; /** \ingroup payload diff --git a/lib/install.c b/lib/install.c index e99bb70e7..fa7bce8b9 100644 --- a/lib/install.c +++ b/lib/install.c @@ -15,20 +15,8 @@ /*@access Header@*/ /* XXX compared with NULL */ /** - * Private data for cpio callback. - */ -typedef struct callbackInfo_s { - unsigned long archiveSize; - rpmCallbackFunction notify; - const char ** specFilePtr; - Header h; - rpmCallbackData notifyData; - const void * pkgKey; -} * cbInfo; - -/* XXX add more tags */ -/** * Macros to be defined from per-header tag values. + * @todo Should other macros be added from header when installing a package? */ static struct tagMacro { const char * macroname; /*!< Macro name to define. */ @@ -401,42 +389,19 @@ static int markReplacedFiles(const rpmTransactionSet ts, const TFI_t fi) } /** - */ -static void callback(struct cpioCallbackInfo * cpioInfo, void * data) -{ - cbInfo cbi = data; - - if (cbi->notify) - (void)cbi->notify(cbi->h, RPMCALLBACK_INST_PROGRESS, - cpioInfo->bytesProcessed, - cbi->archiveSize, cbi->pkgKey, cbi->notifyData); - - if (cbi->specFilePtr) { - const char * t = cpioInfo->file + strlen(cpioInfo->file) - 5; - if (!strcmp(t, ".spec")) - *cbi->specFilePtr = xstrdup(cpioInfo->file); - } -} - -/** * Setup payload map and install payload archive. * * @todo Add endian tag so that srpm MD5 sums can be verified when installed. * * @param ts transaction set * @param fi transaction element file info (NULL means all files) - * @retval specFile address of spec file name - * @param archiveSize @todo Document. * @param allFiles install all files? * @return 0 on success */ -static int installArchive(const rpmTransactionSet ts, TFI_t fi, - /*@out@*/ const char ** specFile, int archiveSize, - int allFiles) +static int installArchive(const rpmTransactionSet ts, TFI_t fi, int allFiles) { struct availablePackage * alp = fi->ap; const char * failedFile = NULL; - cbInfo cbi = alloca(sizeof(*cbi)); char * rpmio_flags; int saveerrno; int rc; @@ -448,18 +413,11 @@ static int installArchive(const rpmTransactionSet ts, TFI_t fi, return 0; } - cbi->archiveSize = archiveSize; /* arg9 */ - cbi->notify = ts->notify; /* arg4 */ - cbi->notifyData = ts->notifyData; /* arg5 */ - cbi->specFilePtr = specFile; /* arg8 */ - cbi->h = headerLink(fi->h); /* arg7 */ - cbi->pkgKey = alp->key; /* arg6 */ - - if (specFile) *specFile = NULL; - - if (ts->notify) - (void)ts->notify(fi->h, RPMCALLBACK_INST_PROGRESS, 0, archiveSize, - alp->key, ts->notifyData); + { uint_32 * asp; + rc = headerGetEntry(fi->h, RPMTAG_ARCHIVESIZE, NULL, + (void **) &asp, NULL); + fi->archiveSize = (rc ? *asp : 0); + } /* Retrieve type of payload compression. */ { const char * payload_compressor = NULL; @@ -479,13 +437,10 @@ static int installArchive(const rpmTransactionSet ts, TFI_t fi, { FD_t cfd; (void) Fflush(alp->fd); cfd = Fdopen(fdDup(Fileno(alp->fd)), rpmio_flags); - rc = cpioInstallArchive(cfd, fi, - ((ts->notify && archiveSize) || specFile) ? callback : NULL, - cbi, &failedFile); + rc = cpioInstallArchive(ts, fi, cfd, &failedFile); saveerrno = errno; /* XXX FIXME: Fclose with libio destroys errno */ Fclose(cfd); } - headerFree(cbi->h); if (rc) { /* @@ -498,12 +453,6 @@ static int installArchive(const rpmTransactionSet ts, TFI_t fi, (failedFile != NULL ? failedFile : ""), cpioStrerror(rc)); rc = 1; - } else if (ts->notify) { - if (archiveSize == 0) - archiveSize = 100; - (void)ts->notify(fi->h, RPMCALLBACK_INST_PROGRESS, - archiveSize, archiveSize, alp->key, ts->notifyData); - rc = 0; } if (failedFile) @@ -558,8 +507,6 @@ static int installSources(const rpmTransactionSet ts, TFI_t fi, const char * _sourcedir = rpmGenPath(ts->rootDir, "%{_sourcedir}", ""); const char * _specdir = rpmGenPath(ts->rootDir, "%{_specdir}", ""); const char * specFile = NULL; - int specFileIndex = -1; - uint_32 * archiveSizePtr = NULL; int rc = 0; int i; @@ -591,90 +538,47 @@ static int installSources(const rpmTransactionSet ts, TFI_t fi, } } + /* Build dnl/dil with {_sourcedir, _specdir} as values. */ if (i < fi->fc) { - char *t = xmalloc(strlen(_specdir) + strlen(fi->apath[i]) + 5); - (void)stpcpy(stpcpy(t, _specdir), "/"); - fi->dnl[fi->dil[i]] = t; - fi->bnl[i] = xstrdup(fi->apath[i]); - specFileIndex = i; + int speclen = strlen(_specdir) + 2; + int sourcelen = strlen(_sourcedir) + 2; + char * t; + + if (fi->dnl) { + free((void *)fi->dnl); fi->dnl = NULL; + } + + fi->dc = 2; + fi->dnl = xmalloc(fi->dc * sizeof(*fi->dnl) + fi->fc * sizeof(*fi->dil) + + speclen + sourcelen); + fi->dil = (int *)(fi->dnl + fi->dc); + memset(fi->dil, 0, fi->fc * sizeof(*fi->dil)); + fi->dil[i] = 1; + fi->dnl[0] = t = (char *)(fi->dil + fi->fc); + fi->dnl[1] = t = stpcpy( stpcpy(t, _sourcedir), "/") + 1; + (void) stpcpy( stpcpy(t, _specdir), "/"); + + t = xmalloc(speclen + strlen(fi->bnl[i]) + 1); + (void) stpcpy( stpcpy( stpcpy(t, _specdir), "/"), fi->bnl[i]); + specFile = t; } else { rpmError(RPMERR_NOSPEC, _("source package contains no .spec file\n")); rc = 2; goto exit; } - if (ts->notify) - (void)ts->notify(fi->h, RPMCALLBACK_INST_START, 0, 0, - NULL, ts->notifyData); - - if (!headerGetEntry(fi->h, RPMTAG_ARCHIVESIZE, NULL, - (void **) &archiveSizePtr, NULL)) - archiveSizePtr = NULL; - - { const char * currDir = currentDirectory(); - Chdir(_sourcedir); - rc = installArchive(ts, fi, - specFileIndex >= 0 ? NULL : &specFile, - archiveSizePtr ? *archiveSizePtr : 0, - 1); - - Chdir(currDir); - free((void *)currDir); - if (rc) { - rc = 2; - goto exit; - } - } - - if (specFileIndex == -1) { - char * cSpecFile; - char * iSpecFile; + rc = installArchive(ts, fi, 1); - if (specFile == NULL) { - rpmError(RPMERR_NOSPEC, - _("source package contains no .spec file\n")); - rc = 1; - goto exit; - } - - /* - * This logic doesn't work if _specdir and _sourcedir are on - * different filesystems, but we only do this on v1 source packages - * so I don't really care much. - */ - iSpecFile = alloca(strlen(_sourcedir) + strlen(specFile) + 2); - (void)stpcpy(stpcpy(stpcpy(iSpecFile, _sourcedir), "/"), specFile); - - cSpecFile = alloca(strlen(_specdir) + strlen(specFile) + 2); - (void)stpcpy(stpcpy(stpcpy(cSpecFile, _specdir), "/"), specFile); - - free((void *)specFile); - - if (strcmp(iSpecFile, cSpecFile)) { - rpmMessage(RPMMESS_DEBUG, - _("renaming %s to %s\n"), iSpecFile, cSpecFile); - if ((rc = Rename(iSpecFile, cSpecFile))) { - rpmError(RPMERR_RENAME, _("rename of %s to %s failed: %s\n"), - iSpecFile, cSpecFile, strerror(errno)); - rc = 2; - goto exit; - } - } - - if (specFilePtr) - *specFilePtr = xstrdup(cSpecFile); - } else { - if (specFilePtr) { - const char * dn = fi->dnl[fi->dil[specFileIndex]]; - const char * bn = fi->bnl[specFileIndex]; - char * t = xmalloc(strlen(dn) + strlen(bn) + 1); - (void)stpcpy( stpcpy(t, dn), bn); - *specFilePtr = t; - } + if (rc) { + rc = 2; + goto exit; } - rc = 0; exit: + if (rc == 0 && specFile && specFilePtr) + *specFilePtr = specFile; + else + free((void *)specFile); if (_specdir) free((void *)_specdir); if (_sourcedir) free((void *)_sourcedir); return rc; @@ -904,7 +808,6 @@ static int installActions(const rpmTransactionSet ts, TFI_t fi) int installBinaryPackage(const rpmTransactionSet ts, TFI_t fi) { static char * stepName = "install"; - struct availablePackage * alp = fi->ap; Header oldH = NULL; int otherOffset = 0; int ec = 2; /* assume error return */ @@ -1007,9 +910,7 @@ int installBinaryPackage(const rpmTransactionSet ts, TFI_t fi) ts->chrootDone = 1; } - if (fi->fc > 0 && !(ts->transFlags & RPMTRANS_FLAG_JUSTDB)) { - uint_32 archiveSize, * asp; setFileOwners(fi); @@ -1017,17 +918,8 @@ int installBinaryPackage(const rpmTransactionSet ts, TFI_t fi) if (rc) goto exit; - rc = headerGetEntry(fi->h, RPMTAG_ARCHIVESIZE, NULL, - (void **) &asp, NULL); - archiveSize = (rc ? *asp : 0); - - if (ts->notify) - (void)ts->notify(fi->h, RPMCALLBACK_INST_START, 0, 0, - alp->key, ts->notifyData); - - rc = installArchive(ts, fi, NULL, archiveSize, 0); + rc = installArchive(ts, fi, 0); - /* XXX WTFO? RPMCALLBACK_INST_STOP event? */ if (rc) goto exit; } diff --git a/lib/install.h b/lib/install.h index 8029a5cdd..1ba965292 100644 --- a/lib/install.h +++ b/lib/install.h @@ -66,7 +66,7 @@ enum fileTypes { SOCK = 12, /*!< socket */ }; -/*@abstract@*/ typedef struct transactionFileInfo_s * TFI_t; +typedef /*@abstract@*/ struct transactionFileInfo_s * TFI_t; #ifdef __cplusplus extern "C" { diff --git a/lib/rollback.h b/lib/rollback.h index 84b274149..af9a69b6b 100644 --- a/lib/rollback.h +++ b/lib/rollback.h @@ -55,6 +55,7 @@ struct transactionFileInfo_s { uid_t * fuids; gid_t * fgids; int * fmapflags; + unsigned int archiveSize; int magic; #define TFIMAGIC 0x09697923 /* these are for TR_ADDED packages */ diff --git a/lib/rpmlib.h b/lib/rpmlib.h index f8b5d0e22..e53642edf 100644 --- a/lib/rpmlib.h +++ b/lib/rpmlib.h @@ -692,7 +692,8 @@ Header XrpmdbNextIterator(rpmdbMatchIterator mi, const char * f, unsigned int l) * @param h header * @return 0 on success */ -int rpmdbAdd(rpmdb rpmdb, int iid, Header h); /*@modifies h @*/ +int rpmdbAdd(rpmdb rpmdb, int iid, Header h) + /*@modifies h @*/; /** \ingroup rpmdb * Remove package header from rpm database and indices. |