summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorjbj <devnull@localhost>2001-01-23 23:03:28 +0000
committerjbj <devnull@localhost>2001-01-23 23:03:28 +0000
commit8b7b911a17f187822f6e72b162ef3bea39366176 (patch)
tree8790acb6f1649782d0949a69ef3711170959e627 /lib
parent7eb91a51526e6d85cbcec1760d7a18144b1aa9b5 (diff)
downloadlibrpm-tizen-8b7b911a17f187822f6e72b162ef3bea39366176.tar.gz
librpm-tizen-8b7b911a17f187822f6e72b162ef3bea39366176.tar.bz2
librpm-tizen-8b7b911a17f187822f6e72b162ef3bea39366176.zip
Rip out cpioFileMap.
CVS patchset: 4493 CVS date: 2001/01/23 23:03:28
Diffstat (limited to 'lib')
-rw-r--r--lib/cpio.c125
-rw-r--r--lib/cpio.h14
-rw-r--r--lib/depends.h19
-rw-r--r--lib/install.c216
-rw-r--r--lib/misc.c11
-rw-r--r--lib/transaction.c147
6 files changed, 289 insertions, 243 deletions
diff --git a/lib/cpio.c b/lib/cpio.c
index ae0bf9c00..c010ae43e 100644
--- a/lib/cpio.c
+++ b/lib/cpio.c
@@ -23,6 +23,20 @@
#define TRAILER "TRAILER!!!"
/** \ingroup payload
+ * Defines a single file to be included in a cpio payload.
+ */
+struct cpioFileMapping {
+/*@dependent@*/ const char * archivePath; /*!< Path to store in cpio archive. */
+/*@dependent@*/ const char * dirName; /*!< Payload file directory. */
+/*@dependent@*/ const char * baseName; /*!< Payload file base name. */
+/*@dependent@*/ const char * md5sum; /*!< File MD5 sum (NULL disables). */
+ mode_t finalMode; /*!< Mode of payload file (from header). */
+ uid_t finalUid; /*!< Uid of payload file (from header). */
+ gid_t finalGid; /*!< Gid of payload file (from header). */
+ cpioMapFlags mapFlags;
+};
+
+/** \ingroup payload
* Keeps track of set of all hard linked files in archive.
*/
struct hardLink {
@@ -121,43 +135,20 @@ static const char * mapMd5sum(const void * this) {
}
struct mapi {
- union {
- const struct cpioFileMapping * mappings;
- TFI_t fi;
- } u;
- int numMappings;
+ TFI_t fi;
int i;
+ struct cpioFileMapping map;
};
-static int cpioFileMapCmp(const void * a, const void * b) {
- const char * afn = ((const struct cpioFileMapping *)a)->archivePath;
- const char * bfn = ((const struct cpioFileMapping *)b)->archivePath;
-
- /* Match payloads with ./ prefixes as well. */
- if (afn[0] == '.' && afn[1] == '/') afn += 2;
- if (bfn[0] == '.' && bfn[1] == '/') bfn += 2;
-
- return strcmp(afn, bfn);
-}
-
-static const void * mapFind(const void * this, const char * hdrPath) {
- const struct mapi * mapi = this;
- const struct cpioFileMapping * map;
- struct cpioFileMapping needle;
-
- needle.archivePath = hdrPath;
- map = bsearch(&needle, mapi->u.mappings, mapi->numMappings,
- sizeof(needle), cpioFileMapCmp);
- return map;
-}
-
static const void * mapLink(const void * this) {
- const struct cpioFileMapping * map = this;
- return map;
+ const struct cpioFileMapping * omap = this;
+ struct cpioFileMapping * nmap = xcalloc(sizeof(*nmap), 1);
+ *nmap = *omap; /* structure assignment */
+ return nmap;
}
static void mapFree(const void * this) {
- return;
+ free((void *)this);
}
static void mapFreeIterator(/*@only@*/ const void * this) {
@@ -171,27 +162,77 @@ static void * mapInitIterator(const void * this, int numMappings) {
if (this == NULL)
return NULL;
mapi = xcalloc(sizeof(*mapi), 1);
- mapi->u.mappings = this;
- mapi->numMappings = numMappings;
+ mapi->fi = (void *)this;
mapi->i = 0;
-
- qsort((void *)mapi->u.mappings, numMappings, sizeof(*mapi->u.mappings),
- cpioFileMapCmp);
-
return mapi;
}
static const void * mapNextIterator(void * this) {
struct mapi * mapi = this;
- const struct cpioFileMapping * map;
+ TFI_t fi = mapi->fi;
+ struct cpioFileMapping * map = &mapi->map;
+ int i = mapi->i;
- if (!(mapi->i < mapi->numMappings))
- return NULL;
- map = mapi->u.mappings + mapi->i;
+ do {
+ if (!((i = mapi->i++) < fi->fc))
+ return NULL;
+ } while (fi->actions && XFA_SKIPPING(fi->actions[i]));
+
+ /* src rpms have simple base name in payload. */
+ map->archivePath = (fi->apath ? fi->apath[i] + fi->striplen : fi->bnl[i]);
+ map->dirName = fi->dnl[fi->dil[i]];
+ map->baseName = fi->bnl[i];
+ map->md5sum = (fi->fmd5s ? fi->fmd5s[i] : NULL);
+ map->finalMode = fi->fmodes[i];
+ map->finalUid = (fi->fuids ? fi->fuids[i] : fi->uid); /* XXX chmod u-s */
+ map->finalGid = (fi->fgids ? fi->fgids[i] : fi->gid); /* XXX chmod g-s */
+ map->mapFlags = (fi->fmapflags ? fi->fmapflags[i] : fi->mapflags);
mapi->i++;
return map;
}
+#ifdef DYING
+static int cpioFileMapCmp(const void * a, const void * b) {
+ const char * afn = ((const struct cpioFileMapping *)a)->archivePath;
+ const char * bfn = ((const struct cpioFileMapping *)b)->archivePath;
+
+ /* Match payloads with ./ prefixes as well. */
+ if (afn[0] == '.' && afn[1] == '/') afn += 2;
+ if (bfn[0] == '.' && bfn[1] == '/') bfn += 2;
+
+ return strcmp(afn, bfn);
+}
+#endif
+
+static int cpioStrCmp(const void * a, const void * b) {
+ const char * afn = *(const char **)a;
+ const char * bfn = *(const char **)b;
+
+ /* Match rpm-4.0 payloads with ./ prefixes. */
+ if (afn[0] == '.' && afn[1] == '/') afn += 2;
+ if (bfn[0] == '.' && bfn[1] == '/') bfn += 2;
+
+ /* If either path is absolute, make it relative. */
+ if (afn[0] == '/') afn += 1;
+ if (bfn[0] == '/') bfn += 1;
+
+ return strcmp(afn, bfn);
+}
+
+static const void * mapFind(void * this, const char * hdrPath) {
+ struct mapi * mapi = this;
+ const TFI_t fi = mapi->fi;
+ const char ** p;
+
+ p = bsearch(&hdrPath, fi->apath, fi->fc, sizeof(hdrPath), cpioStrCmp);
+ if (p == NULL) {
+ fprintf(stderr, "*** not mapped %s\n", hdrPath);
+ return NULL;
+ }
+ mapi->i = p - fi->apath;
+ return mapNextIterator(this);
+}
+
/**
* Read data from payload.
* @param cfd payload file handle
@@ -822,7 +863,7 @@ int cpioInstallArchive(FD_t cfd, const void * mappings,
const char ** failedFile)
{
struct cpioHeader ch, *hdr = &ch;
- const void * mapi = mapInitIterator(mappings, numMappings);
+ void * mapi = mapInitIterator(mappings, numMappings);
const void * map = NULL;
struct cpioCallbackInfo cbInfo = { NULL, 0, 0, 0 };
struct hardLink * links = NULL;
@@ -1230,7 +1271,7 @@ int cpioBuildArchive(FD_t cfd, const void * mappings,
int numMappings, cpioCallback cb, void * cbData,
unsigned int * archiveSize, const char ** failedFile)
{
- const void * mapi = mapInitIterator(mappings, numMappings);
+ void * mapi = mapInitIterator(mappings, numMappings);
const void * map;
struct cpioCallbackInfo cbInfo = { NULL, 0, 0, 0 };
struct cpioCrcPhysicalHeader hdr;
diff --git a/lib/cpio.h b/lib/cpio.h
index 99c998687..4f24415d9 100644
--- a/lib/cpio.h
+++ b/lib/cpio.h
@@ -62,20 +62,6 @@ typedef enum cpioMapFlags_e {
} cpioMapFlags;
/** \ingroup payload
- * Defines a single file to be included in a cpio payload.
- */
-struct cpioFileMapping {
-/*@dependent@*/ const char * archivePath; /*!< Path to store in cpio archive. */
-/*@dependent@*/ const char * dirName; /*!< Payload file directory. */
-/*@dependent@*/ const char * baseName; /*!< Payload file base name. */
-/*@dependent@*/ const char * md5sum; /*!< File MD5 sum (NULL disables). */
- mode_t finalMode; /*!< Mode of payload file (from header). */
- uid_t finalUid; /*!< Uid of payload file (from header). */
- gid_t finalGid; /*!< Gid of payload file (from header). */
- cpioMapFlags mapFlags;
-};
-
-/** \ingroup payload
* The first argument passed in a cpio progress callback.
*
* @note When building the cpio payload, only "file" is filled in.
diff --git a/lib/depends.h b/lib/depends.h
index b2d4b004a..2e81e00f8 100644
--- a/lib/depends.h
+++ b/lib/depends.h
@@ -121,7 +121,7 @@ struct transactionElement {
/**
*/
typedef int (*HGE_t) (Header h, int_32 tag, /*@out@*/ int_32 * type,
- /*@out@*/ const void ** p, /*@out@*/int_32 * c)
+ /*@out@*/ void ** p, /*@out@*/int_32 * c)
/*@modifies *type, *p, *c @*/;
/**
@@ -133,9 +133,6 @@ struct transactionFileInfo_s {
/*@dependent@*/ struct fingerPrint_s * fps; /*!< file fingerprints */
HGE_t hge;
Header h; /*!< Package header */
- const char * n; /*!< Package name */
- const char * v; /*!< Package version */
- const char * r; /*!< Package release */
const uint_32 * fflags; /*!< File flags (from header) */
const uint_32 * fsizes; /*!< File sizes (from header) */
const char ** bnl; /*!< Base names (from header) */
@@ -146,7 +143,8 @@ struct transactionFileInfo_s {
const int * odil; /*!< Original Directory indices (from header) */
const char ** fmd5s; /*!< file MD5 sums (from header) */
const char ** flinks; /*!< file links (from header) */
- const uint_16 * fmodes; /*!< file modes (from header) */
+/* XXX setuid/setgid bits are turned off if fsuer/fgroup doesn't map. */
+ uint_16 * fmodes; /*!< file modes (from header) */
char * fstates; /*!< file states (from header) */
const char ** fuser; /*!< file owner(s) */
const char ** fgroup; /*!< file group(s) */
@@ -155,6 +153,14 @@ struct transactionFileInfo_s {
int dc; /*!< No. of directories. */
int bnlmax; /*!< Length (in bytes) of longest base name. */
int dnlmax; /*!< Length (in bytes) of longest dir name. */
+ int mapflags;
+ int striplen;
+ const char ** apath;
+ uid_t uid;
+ gid_t gid;
+ uid_t * fuids;
+ gid_t * fgids;
+ int * fmapflags;
int magic;
#define TFIMAGIC 0x09697923
/* these are for TR_ADDED packages */
@@ -206,6 +212,9 @@ struct problemsSet {
extern "C" {
#endif
+#define XFA_SKIPPING(_a) \
+ ((_a) == FA_SKIP || (_a) == FA_SKIPNSTATE || (_a) == FA_SKIPNETSHARED || (_a) == FA_SKIPMULTILIB)
+
/**
*/
void loadFi(Header h, struct transactionFileInfo_s * fi);
diff --git a/lib/install.c b/lib/install.c
index fa11fc299..8d5dc6225 100644
--- a/lib/install.c
+++ b/lib/install.c
@@ -32,7 +32,6 @@ typedef struct callbackInfo_s {
* Header file info, gathered per-file, rather than per-tag.
*/
typedef struct fileInfo_s {
-/*@dependent@*/ const char * cpioPath;
/*@dependent@*/ const char * dn; /* relative to root */
/*@dependent@*/ const char * bn;
/*@observer@*/ const char * bnsuffix;
@@ -137,51 +136,49 @@ static void freeFileMemory( /*@only@*/ fileMemory fileMem)
* @param fi transaction file info (NULL for source package)
* @param h header
* @retval memPtr address of allocated memory from header access
- * @retval fileCountPtr address of install file count
* @retval files address of install file information
- * @param stripPrefixLength no. bytes of file prefix to skip
* @param actions array of file dispositions
* @return 0 always
*/
static int assembleFileList(TFI_t fi, Header h,
- /*@out@*/ fileMemory * memPtr,
- /*@out@*/ int * fileCountPtr,
- /*@out@*/ XFI_t * filesPtr,
- int stripPrefixLength)
+ /*@out@*/ fileMemory * memPtr, /*@out@*/ XFI_t * filesPtr)
{
fileMemory mem = newFileMemory();
XFI_t files;
XFI_t file;
- int fileCount;
int i;
*memPtr = mem;
- if (!headerIsEntry(h, RPMTAG_BASENAMES)) return 0;
+ if (fi->fc == 0)
+ return 0;
+
+ fi->fuids = xcalloc(sizeof(*fi->fuids), fi->fc);
+ fi->fgids = xcalloc(sizeof(*fi->fgids), fi->fc);
if (headerIsEntry(h, RPMTAG_ORIGBASENAMES)) {
- buildOrigFileList(h, &mem->cpioNames, fileCountPtr);
+ buildOrigFileList(h, &fi->apath, NULL);
} else {
- rpmBuildFileList(h, &mem->cpioNames, fileCountPtr);
+ rpmBuildFileList(h, &fi->apath, NULL);
}
- fileCount = *fileCountPtr;
-
- files = *filesPtr = mem->files = xcalloc(fileCount, sizeof(*mem->files));
+ files = *filesPtr = mem->files = xcalloc(fi->fc, sizeof(*mem->files));
- for (i = 0, file = files; i < fileCount; i++, file++) {
+ for (i = 0, file = files; i < fi->fc; i++, file++) {
file->state = RPMFILE_STATE_NORMAL;
file->action = (fi->actions ? fi->actions[i] : FA_UNKNOWN);
file->install = 1;
file->dn = fi->dnl[fi->dil[i]];
file->bn = fi->bnl[i];
- file->cpioPath = mem->cpioNames[i] + stripPrefixLength;
file->md5sum = (fi->fmd5s ? fi->fmd5s[i] : NULL);
file->mode = fi->fmodes[i];
file->size = fi->fsizes[i];
file->flags = fi->fflags[i];
+ fi->fuids[i] = file->uid = fi->uid;
+ fi->fgids[i] = file->gid = fi->gid;
+
rpmMessage(RPMMESS_DEBUG, _(" file: %s%s action: %s\n"),
file->dn, file->bn, fileActionString(file->action));
}
@@ -192,37 +189,42 @@ static int assembleFileList(TFI_t fi, Header h,
/**
* Localize user/group id's.
* @param h header
+ * @param fi transaction element file info
* @param files install file information
- * @param fileCount install file count
*/
-static void setFileOwners(Header h, XFI_t files, int fileCount)
+static void setFileOwners(Header h, TFI_t fi, XFI_t files)
{
- const char ** fileOwners;
- const char ** fileGroups;
XFI_t file;
int i;
- headerGetEntry(h, RPMTAG_FILEUSERNAME, NULL, (void **) &fileOwners, NULL);
- headerGetEntry(h, RPMTAG_FILEGROUPNAME, NULL, (void **) &fileGroups, NULL);
+ if (fi->fuser == NULL)
+ headerGetEntryMinMemory(h, RPMTAG_FILEUSERNAME, NULL,
+ (const void **) &fi->fuser, NULL);
+ if (fi->fgroup == NULL)
+ headerGetEntryMinMemory(h, RPMTAG_FILEGROUPNAME, NULL,
+ (const void **) &fi->fgroup, NULL);
- for (i = 0, file = files; i < fileCount; i++, file++) {
- if (unameToUid(fileOwners[i], &file->uid)) {
+ for (i = 0, file = files; i < fi->fc; i++, file++) {
+ if (unameToUid(fi->fuser[i], &file->uid)) {
rpmMessage(RPMMESS_WARNING,
- _("user %s does not exist - using root\n"), fileOwners[i]);
+ _("user %s does not exist - using root\n"), fi->fuser[i]);
file->uid = 0;
file->mode &= ~S_ISUID; /* turn off the suid bit */
+ /* XXX this diddles header memory. */
+ fi->fmodes[i] &= ~S_ISUID; /* turn off the suid bit */
}
- if (gnameToGid(fileGroups[i], &file->gid)) {
+ if (gnameToGid(fi->fgroup[i], &file->gid)) {
rpmMessage(RPMMESS_WARNING,
- _("group %s does not exist - using root\n"), fileGroups[i]);
+ _("group %s does not exist - using root\n"), fi->fgroup[i]);
file->gid = 0;
file->mode &= ~S_ISGID; /* turn off the sgid bit */
+ /* XXX this diddles header memory. */
+ fi->fmodes[i] &= ~S_ISGID; /* turn off the sgid bit */
}
+ fi->fuids[i] = file->uid;
+ fi->fgids[i] = file->gid;
}
-
- free(fileOwners);
- free(fileGroups);
}
#ifdef DYING
@@ -277,7 +279,7 @@ static void trimChangelog(Header h)
static int mergeFiles(Header h, Header newH, TFI_t fi)
{
enum fileActions * actions = fi->actions;
- int i, j, k, fileCount;
+ int i, j, k, fc;
int_32 type, count, dirNamesCount, dirCount;
void * data, * newdata;
int_32 * dirIndexes, * newDirIndexes;
@@ -310,9 +312,9 @@ static int mergeFiles(Header h, Header newH, TFI_t fi)
headerGetEntry(h, RPMTAG_SIZE, NULL, (void **) &fileSizes, NULL);
fileSize = *fileSizes;
headerGetEntry(newH, RPMTAG_FILESIZES, NULL, (void **) &fileSizes, &count);
- for (i = 0, fileCount = 0; i < count; i++)
+ for (i = 0, fc = 0; i < count; i++)
if (actions[i] != FA_SKIPMULTILIB) {
- fileCount++;
+ fc++;
fileSize += fileSizes[i];
}
headerModifyEntry(h, RPMTAG_SIZE, RPM_INT32_TYPE, &fileSize, 1);
@@ -323,36 +325,35 @@ static int mergeFiles(Header h, Header newH, TFI_t fi)
switch (type) {
case RPM_CHAR_TYPE:
case RPM_INT8_TYPE:
- newdata = xmalloc(fileCount * sizeof(int_8));
+ newdata = xmalloc(fc * sizeof(int_8));
for (j = 0, k = 0; j < count; j++)
if (actions[j] != FA_SKIPMULTILIB)
((int_8 *) newdata)[k++] = ((int_8 *) data)[j];
- headerAddOrAppendEntry(h, mergeTags[i], type, newdata,
- fileCount);
+ headerAddOrAppendEntry(h, mergeTags[i], type, newdata, fc);
free (newdata);
break;
case RPM_INT16_TYPE:
- newdata = xmalloc(fileCount * sizeof(int_16));
+ newdata = xmalloc(fc * sizeof(int_16));
for (j = 0, k = 0; j < count; j++)
if (actions[j] != FA_SKIPMULTILIB)
((int_16 *) newdata)[k++] = ((int_16 *) data)[j];
- headerAddOrAppendEntry(h, mergeTags[i], type, newdata, fileCount);
+ headerAddOrAppendEntry(h, mergeTags[i], type, newdata, fc);
free (newdata);
break;
case RPM_INT32_TYPE:
- newdata = xmalloc(fileCount * sizeof(int_32));
+ newdata = xmalloc(fc * sizeof(int_32));
for (j = 0, k = 0; j < count; j++)
if (actions[j] != FA_SKIPMULTILIB)
((int_32 *) newdata)[k++] = ((int_32 *) data)[j];
- headerAddOrAppendEntry(h, mergeTags[i], type, newdata, fileCount);
+ headerAddOrAppendEntry(h, mergeTags[i], type, newdata, fc);
free (newdata);
break;
case RPM_STRING_ARRAY_TYPE:
- newdata = xmalloc(fileCount * sizeof(char *));
+ newdata = xmalloc(fc * sizeof(char *));
for (j = 0, k = 0; j < count; j++)
if (actions[j] != FA_SKIPMULTILIB)
((char **) newdata)[k++] = ((char **) data)[j];
- headerAddOrAppendEntry(h, mergeTags[i], type, newdata, fileCount);
+ headerAddOrAppendEntry(h, mergeTags[i], type, newdata, fc);
free (newdata);
free (data);
break;
@@ -371,11 +372,11 @@ static int mergeFiles(Header h, Header newH, TFI_t fi)
headerGetEntryMinMemory(h, RPMTAG_DIRNAMES, NULL, (const void **) &data,
&dirNamesCount);
- dirNames = xcalloc(dirNamesCount + fileCount, sizeof(char *));
+ dirNames = xcalloc(dirNamesCount + fc, sizeof(char *));
for (i = 0; i < dirNamesCount; i++)
dirNames[i] = ((char **) data)[i];
dirCount = dirNamesCount;
- newdata = xmalloc(fileCount * sizeof(int_32));
+ newdata = xmalloc(fc * sizeof(int_32));
for (i = 0, k = 0; i < count; i++) {
if (actions[i] == FA_SKIPMULTILIB)
continue;
@@ -386,8 +387,7 @@ static int mergeFiles(Header h, Header newH, TFI_t fi)
dirNames[dirCount++] = newDirNames[newDirIndexes[i]];
((int_32 *) newdata)[k++] = j;
}
- headerAddOrAppendEntry(h, RPMTAG_DIRINDEXES, RPM_INT32_TYPE, newdata,
- fileCount);
+ headerAddOrAppendEntry(h, RPMTAG_DIRINDEXES, RPM_INT32_TYPE, newdata, fc);
if (dirCount > dirNamesCount)
headerAddOrAppendEntry(h, RPMTAG_DIRNAMES, RPM_STRING_ARRAY_TYPE,
dirNames + dirNamesCount,
@@ -545,9 +545,10 @@ static void callback(struct cpioCallbackInfo * cpioInfo, void * data)
*
* @todo Add endian tag so that srpm MD5 sums can ber verified when installed.
*
+ * @param ts transaction set
+ * @param fi transaction element file info
* @param fd file handle of package (positioned at payload)
* @param files files to install (NULL means "all files")
- * @param fileCount no. files to install
* @param notify callback function
* @param notifyData callback private data
* @param pkgKey package private data (e.g. file name)
@@ -557,24 +558,22 @@ static void callback(struct cpioCallbackInfo * cpioInfo, void * data)
* @return 0 on success
*/
static int installArchive(const rpmTransactionSet ts, TFI_t fi,
- FD_t fd, XFI_t files, int fileCount,
+ FD_t fd, XFI_t files,
rpmCallbackFunction notify, rpmCallbackData notifyData,
const void * pkgKey, Header h,
/*@out@*/ const char ** specFile, int archiveSize)
{
- struct cpioFileMapping * map = NULL;
- int mappedFiles = 0;
+ const void * cpioMap = NULL;
+ int cpioMapCnt = 0;
const char * failedFile = NULL;
cbInfo cbi = alloca(sizeof(*cbi));
char * rpmio_flags;
- FD_t cfd;
int saveerrno;
int rc;
- if (!files) {
+ if (files == NULL) {
/* install all files */
- fileCount = 0;
- } else if (!fileCount) {
+ } else if (fi->fc == 0) {
/* no files to install */
return 0;
}
@@ -589,11 +588,14 @@ static int installArchive(const rpmTransactionSet ts, TFI_t fi,
if (specFile) *specFile = NULL;
if (files) {
+#ifdef DYING
+ struct cpioFileMapping * map = NULL;
+ int mappedFiles;
XFI_t file;
int i;
- map = alloca(sizeof(*map) * fileCount);
- for (i = 0, mappedFiles = 0, file = files; i < fileCount; i++, file++) {
+ map = alloca(sizeof(*map) * fi->fc);
+ for (i = 0, mappedFiles = 0, file = files; i < fi->fc; i++, file++) {
if (!file->install) continue;
map[mappedFiles].archivePath = file->cpioPath;
@@ -611,6 +613,12 @@ static int installArchive(const rpmTransactionSet ts, TFI_t fi,
CPIO_MAP_UID | CPIO_MAP_GID;
mappedFiles++;
}
+ cpioMap = map;
+ cpioMapCnt = mappedFiles;
+#else
+ cpioMap = fi;
+ cpioMapCnt = fi->fc;
+#endif
}
if (notify)
@@ -632,13 +640,15 @@ static int installArchive(const rpmTransactionSet ts, TFI_t fi,
t = stpcpy(t, ".bzdio");
}
- (void) Fflush(fd);
- cfd = Fdopen(fdDup(Fileno(fd)), rpmio_flags);
- rc = cpioInstallArchive(cfd, map, mappedFiles,
+ { FD_t cfd;
+ (void) Fflush(fd);
+ cfd = Fdopen(fdDup(Fileno(fd)), rpmio_flags);
+ rc = cpioInstallArchive(cfd, cpioMap, cpioMapCnt,
((notify && archiveSize) || specFile) ? callback : NULL,
cbi, &failedFile);
- saveerrno = errno; /* XXX FIXME: Fclose with libio destroys errno */
- Fclose(cfd);
+ saveerrno = errno; /* XXX FIXME: Fclose with libio destroys errno */
+ Fclose(cfd);
+ }
headerFree(cbi->h);
if (rc) {
@@ -717,13 +727,10 @@ static int installSources(Header h, const char * rootDir, FD_t fd,
int specFileIndex = -1;
const char * _sourcedir = rpmGenPath(rootDir, "%{_sourcedir}", "");
const char * _specdir = rpmGenPath(rootDir, "%{_specdir}", "");
- int fileCount = 0;
uint_32 * archiveSizePtr = NULL;
fileMemory fileMem = NULL;
XFI_t files = NULL, file;
int i;
- uid_t currUid = getuid();
- gid_t currGid = getgid();
int rc = 0;
rpmMessage(RPMMESS_DEBUG, _("installing a source package\n"));
@@ -740,33 +747,41 @@ static int installSources(Header h, const char * rootDir, FD_t fd,
goto exit;
}
+ fi->type = TR_ADDED;
loadFi(h, fi);
-
- assembleFileList(fi, h, &fileMem, &fileCount, &files, 0);
-
- for (i = 0, file = files; i < fileCount; i++, file++) {
- file->uid = currUid;
- file->gid = currGid;
+ if (fi->fmd5s) { /* DYING */
+ free((void **)fi->fmd5s); fi->fmd5s = NULL;
}
+ if (fi->fmapflags) { /* DYING */
+ free((void **)fi->fmapflags); fi->fmapflags = NULL;
+ }
+ fi->uid = getuid();
+ fi->gid = getgid();
+ fi->striplen = 0;
+ fi->mapflags = CPIO_MAP_PATH | CPIO_MAP_MODE | CPIO_MAP_UID | CPIO_MAP_GID;
+
+ assembleFileList(fi, h, &fileMem, &files);
+ i = fi->fc;
+ file = files + i;
if (headerIsEntry(h, RPMTAG_COOKIE))
- for (i = 0, file = files; i < fileCount; i++, file++)
+ for (i = 0, file = files; i < fi->fc; i++, file++)
if (file->flags & RPMFILE_SPECFILE) break;
- if (i == fileCount) {
+ if (i == fi->fc) {
/* find the spec file by name */
- for (i = 0, file = files; i < fileCount; i++, file++) {
- const char * t = file->cpioPath;
- t += strlen(file->cpioPath) - 5;
- if (!strcmp(t, ".spec")) break;
+ for (i = 0, file = files; i < fi->fc; i++, file++) {
+ const char * t = fi->apath[i];
+ t += strlen(fi->apath[i]) - 5;
+ if (!strcmp(t, ".spec")) break;
}
}
- if (i < fileCount) {
- char *t = alloca(strlen(_specdir) + strlen(file->cpioPath) + 5);
+ if (i < fi->fc) {
+ char *t = alloca(strlen(_specdir) + strlen(fi->apath[i]) + 5);
(void)stpcpy(stpcpy(t, _specdir), "/");
file->dn = t;
- file->bn = file->cpioPath;
+ file->bn = fi->apath[i];
specFileIndex = i;
} else {
rpmError(RPMERR_NOSPEC, _("source package contains no .spec file\n"));
@@ -783,8 +798,8 @@ static int installSources(Header h, const char * rootDir, FD_t fd,
{ const char * currDir = currentDirectory();
Chdir(_sourcedir);
- rc = installArchive(NULL, NULL, fd, fileCount > 0 ? files : NULL,
- fileCount, notify, notifyData, NULL, h,
+ rc = installArchive(NULL, NULL, fd, fi->fc > 0 ? files : NULL,
+ notify, notifyData, NULL, h,
specFileIndex >= 0 ? NULL : &specFile,
archiveSizePtr ? *archiveSizePtr : 0);
@@ -947,7 +962,6 @@ int installBinaryPackage(const rpmTransactionSet ts, Header h, TFI_t fi)
{
rpmtransFlags transFlags = ts->transFlags;
struct availablePackage * alp = fi->ap;
- int fileCount = 0;
XFI_t files = NULL;
Header oldH = NULL;
int otherOffset = 0;
@@ -961,9 +975,9 @@ int installBinaryPackage(const rpmTransactionSet ts, Header h, TFI_t fi)
if (transFlags & (RPMTRANS_FLAG_JUSTDB | RPMTRANS_FLAG_MULTILIB))
transFlags |= RPMTRANS_FLAG_NOSCRIPTS;
- rpmMessage(RPMMESS_DEBUG, _("package: %s-%s-%s files test = %d\n"),
+ rpmMessage(RPMMESS_DEBUG, _("package: %s-%s-%s has %d files test = %d\n"),
alp->name, alp->version, alp->release,
- transFlags & RPMTRANS_FLAG_TEST);
+ fi->fc, (transFlags & RPMTRANS_FLAG_TEST));
if ((scriptArg = rpmdbCountPackages(ts->rpmdb, alp->name)) < 0)
goto exit;
@@ -982,11 +996,8 @@ int installBinaryPackage(const rpmTransactionSet ts, Header h, TFI_t fi)
rpmdbFreeIterator(mi);
}
- if (!(transFlags & RPMTRANS_FLAG_JUSTDB) &&
- headerIsEntry(h, RPMTAG_BASENAMES))
- {
+ if (!(transFlags & RPMTRANS_FLAG_JUSTDB) && fi->fc > 0) {
const char * p;
- int stripSize;
/*
* Old format relocateable packages need the entire default
@@ -994,8 +1005,10 @@ int installBinaryPackage(const rpmTransactionSet ts, Header h, TFI_t fi)
* need the leading / stripped.
*/
rc = headerGetEntry(h, RPMTAG_DEFAULTPREFIX, NULL, (void **) &p, NULL);
- stripSize = (rc ? strlen(p) + 1 : 1);
- if (assembleFileList(fi, h, &fileMem, &fileCount, &files, stripSize))
+ fi->striplen = (rc ? strlen(p) + 1 : 1);
+ fi->mapflags =
+ CPIO_MAP_PATH | CPIO_MAP_MODE | CPIO_MAP_UID | CPIO_MAP_GID;
+ if (assembleFileList(fi, h, &fileMem, &files))
goto exit;
} else {
files = NULL;
@@ -1033,9 +1046,9 @@ int installBinaryPackage(const rpmTransactionSet ts, Header h, TFI_t fi)
if (files) {
XFI_t file;
- setFileOwners(h, files, fileCount);
+ setFileOwners(h, fi, files);
- for (i = 0, file = files; i < fileCount; i++, file++) {
+ for (i = 0, file = files; i < fi->fc; i++, file++) {
char opath[BUFSIZ];
char * npath;
char * ext;
@@ -1114,29 +1127,26 @@ int installBinaryPackage(const rpmTransactionSet ts, Header h, TFI_t fi)
}
/* the file pointer for fd is pointing at the cpio archive */
- rc = installArchive(ts, fi, alp->fd, files, fileCount,
+ rc = installArchive(ts, fi, alp->fd, files,
ts->notify, ts->notifyData, alp->key,
h, NULL, archiveSize);
if (rc)
goto exit;
}
- { char *fstates = alloca(sizeof(*fstates) * fileCount);
- for (i = 0, file = files; i < fileCount; i++, file++)
+ { char *fstates = alloca(sizeof(*fstates) * fi->fc);
+ for (i = 0, file = files; i < fi->fc; i++, file++)
fstates[i] = file->state;
headerAddEntry(h, RPMTAG_FILESTATES, RPM_CHAR_TYPE, fstates,
- fileCount);
+ fi->fc);
}
if (fileMem) freeFileMemory(fileMem);
fileMem = NULL;
- } else if (transFlags & RPMTRANS_FLAG_JUSTDB) {
- if (headerGetEntry(h, RPMTAG_BASENAMES, NULL, NULL, &fileCount)) {
- char * fstates = alloca(sizeof(*fstates) * fileCount);
- memset(fstates, RPMFILE_STATE_NORMAL, fileCount);
- headerAddEntry(h, RPMTAG_FILESTATES, RPM_CHAR_TYPE, fstates,
- fileCount);
- }
+ } else if (fi->fc > 0 && transFlags & RPMTRANS_FLAG_JUSTDB) {
+ char * fstates = alloca(sizeof(*fstates) * fi->fc);
+ memset(fstates, RPMFILE_STATE_NORMAL, fi->fc);
+ headerAddEntry(h, RPMTAG_FILESTATES, RPM_CHAR_TYPE, fstates, fi->fc);
}
{ int_32 installTime = time(NULL);
diff --git a/lib/misc.c b/lib/misc.c
index 32475198f..65552e6d3 100644
--- a/lib/misc.c
+++ b/lib/misc.c
@@ -478,8 +478,8 @@ static void doBuildFileList(Header h, /*@out@*/ const char *** fileListPtr,
int i;
if (!headerGetEntry(h, baseNameTag, NULL, (void **) &baseNames, &count)) {
- *fileListPtr = NULL;
- *fileCountPtr = 0;
+ if (fileListPtr) *fileListPtr = NULL;
+ if (fileCountPtr) *fileCountPtr = 0;
return; /* no file list */
}
@@ -500,8 +500,11 @@ static void doBuildFileList(Header h, /*@out@*/ const char *** fileListPtr,
free((void *)baseNames);
free((void *)dirNames);
- *fileListPtr = fileNames;
- *fileCountPtr = count;
+ if (fileListPtr)
+ *fileListPtr = fileNames;
+ else
+ free((void *)fileNames);
+ if (fileCountPtr) *fileCountPtr = count;
}
void expandFilelist(Header h)
diff --git a/lib/transaction.c b/lib/transaction.c
index 687d0443e..3ded3716a 100644
--- a/lib/transaction.c
+++ b/lib/transaction.c
@@ -61,9 +61,6 @@ struct diskspaceInfo {
#define XSTRCMP(a, b) ((!(a) && !(b)) || ((a) && (b) && !strcmp((a), (b))))
-#define XFA_SKIPPING(_a) \
- ((_a) == FA_SKIP || (_a) == FA_SKIPNSTATE || (_a) == FA_SKIPNETSHARED || (_a) == FA_SKIPMULTILIB)
-
void loadFi(Header h, TFI_t fi)
{
HGE_t hge;
@@ -76,11 +73,8 @@ void loadFi(Header h, TFI_t fi)
if (h && fi->h == NULL) fi->h = headerLink(h);
- hge(fi->h, RPMTAG_NAME, NULL, (void **) &fi->n, NULL);
- hge(fi->h, RPMTAG_VERSION, NULL, (void **) &fi->v, NULL);
- hge(fi->h, RPMTAG_RELEASE, NULL, (void **) &fi->r, NULL);
-
if (!hge(fi->h, RPMTAG_BASENAMES, NULL, (void **) &fi->bnl, &fi->fc)) {
+fprintf(stderr, "*** BASENAMES not found\n");
fi->dc = 0;
fi->fc = 0;
fi->dnl = NULL;
@@ -90,6 +84,9 @@ void loadFi(Header h, TFI_t fi)
fi->fflags = NULL;
fi->fsizes = NULL;
fi->fstates = NULL;
+ fi->fmd5s = NULL;
+ fi->flinks = NULL;
+ fi->flangs = NULL;
return;
}
@@ -115,9 +112,6 @@ void loadFi(Header h, TFI_t fi)
break;
case TR_REMOVED:
- fi->n = xstrdup(fi->n);
- fi->v = xstrdup(fi->v);
- fi->r = xstrdup(fi->r);
hge(fi->h, RPMTAG_FILEMD5S, NULL, (void **) &fi->fmd5s, NULL);
hge(fi->h, RPMTAG_FILELINKTOS, NULL, (void **) &fi->flinks, NULL);
fi->fsizes = memcpy(xmalloc(fi->fc * sizeof(*fi->fsizes)),
@@ -156,76 +150,79 @@ void loadFi(Header h, TFI_t fi)
void freeFi(TFI_t fi)
{
- if (fi->h) {
- headerFree(fi->h); fi->h = NULL;
- }
- if (fi->actions) {
- free(fi->actions); fi->actions = NULL;
- }
- if (fi->replacedSizes) {
- free(fi->replacedSizes); fi->replacedSizes = NULL;
- }
- if (fi->replaced) {
- free(fi->replaced); fi->replaced = NULL;
- }
- if (fi->bnl) {
- free(fi->bnl); fi->bnl = NULL;
- }
- if (fi->dnl) {
- free(fi->dnl); fi->dnl = NULL;
- }
- if (fi->obnl) {
- free(fi->obnl); fi->obnl = NULL;
- }
- if (fi->odnl) {
- free(fi->odnl); fi->odnl = NULL;
- }
- if (fi->flinks) {
- free(fi->flinks); fi->flinks = NULL;
- }
- if (fi->fmd5s) {
- free(fi->fmd5s); fi->fmd5s = NULL;
+ if (fi->h) {
+ headerFree(fi->h); fi->h = NULL;
+ }
+ if (fi->actions) {
+ free(fi->actions); fi->actions = NULL;
+ }
+ if (fi->replacedSizes) {
+ free(fi->replacedSizes); fi->replacedSizes = NULL;
+ }
+ if (fi->replaced) {
+ free(fi->replaced); fi->replaced = NULL;
+ }
+ if (fi->bnl) {
+ free(fi->bnl); fi->bnl = NULL;
+ }
+ if (fi->dnl) {
+ free(fi->dnl); fi->dnl = NULL;
+ }
+ if (fi->obnl) {
+ free(fi->obnl); fi->obnl = NULL;
+ }
+ if (fi->odnl) {
+ free(fi->odnl); fi->odnl = NULL;
+ }
+ if (fi->flinks) {
+ free(fi->flinks); fi->flinks = NULL;
+ }
+ if (fi->fmd5s) {
+ free(fi->fmd5s); fi->fmd5s = NULL;
+ }
+ if (fi->fuser) {
+ free(fi->fuser); fi->fuser = NULL;
+ }
+ if (fi->fgroup) {
+ free(fi->fgroup); fi->fgroup = NULL;
+ }
+ if (fi->flangs) {
+ free(fi->flangs); fi->flangs = NULL;
+ }
+ if (fi->apath) {
+ free(fi->apath); fi->apath = NULL;
+ }
+ if (fi->fuids) {
+ free(fi->fuids); fi->fuids = NULL;
+ }
+ if (fi->fgids) {
+ free(fi->fgids); fi->fgids = NULL;
+ }
+ if (fi->fmapflags) {
+ free(fi->fmapflags); fi->fmapflags = NULL;
+ }
+
+ switch (fi->type) {
+ case TR_ADDED:
+ break;
+ case TR_REMOVED:
+ if (fi->fsizes) {
+ free((void *)fi->fsizes); fi->fsizes = NULL;
}
- if (fi->fuser) {
- free(fi->fuser); fi->fuser = NULL;
+ if (fi->fflags) {
+ free((void *)fi->fflags); fi->fflags = NULL;
}
- if (fi->fgroup) {
- free(fi->fgroup); fi->fgroup = NULL;
+ if (fi->fmodes) {
+ free((void *)fi->fmodes); fi->fmodes = NULL;
}
- if (fi->flangs) {
- free(fi->flangs); fi->flangs = NULL;
+ if (fi->fstates) {
+ free((void *)fi->fstates); fi->fstates = NULL;
}
-
- switch (fi->type) {
- case TR_ADDED:
- break;
- case TR_REMOVED:
- if (fi->n) {
- free((void *)fi->n); fi->n = NULL;
- }
- if (fi->v) {
- free((void *)fi->v); fi->v = NULL;
- }
- if (fi->r) {
- free((void *)fi->r); fi->r = NULL;
- }
- if (fi->fsizes) {
- free((void *)fi->fsizes); fi->fsizes = NULL;
- }
- if (fi->fflags) {
- free((void *)fi->fflags); fi->fflags = NULL;
- }
- if (fi->fmodes) {
- free((void *)fi->fmodes); fi->fmodes = NULL;
- }
- if (fi->fstates) {
- free((void *)fi->fstates); fi->fstates = NULL;
- }
- if (fi->dil) {
- free((void *)fi->dil); fi->dil = NULL;
- }
- break;
+ if (fi->dil) {
+ free((void *)fi->dil); fi->dil = NULL;
}
+ break;
+ }
}
static void freeFl(rpmTransactionSet ts, TFI_t flList)