transaction.c: revamped decideFileFate() akin to filecmp()
This commit is contained in:
parent
4a4f1c6522
commit
0ee67602ee
@ -161,11 +161,11 @@ int domd5(const char * fn, /*@out@*/ unsigned char * digest, int asAscii)
|
|||||||
* @return 0 on success, 1 on error
|
* @return 0 on success, 1 on error
|
||||||
*/
|
*/
|
||||||
/*@unused@*/ static inline
|
/*@unused@*/ static inline
|
||||||
int mdfile(const char * fn, /*@out@*/ unsigned char * digest)
|
int mdfile(const char * fn, /*@out@*/ char * digest)
|
||||||
/*@globals fileSystem@*/
|
/*@globals fileSystem@*/
|
||||||
/*@modifies digest, fileSystem @*/
|
/*@modifies digest, fileSystem @*/
|
||||||
{
|
{
|
||||||
return domd5(fn, digest, 1);
|
return domd5(fn, (unsigned char *) digest, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -782,30 +782,23 @@ static int sharedCmp(const void * one, const void * two)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static fileAction decideFileFate(const char * dirName,
|
static fileAction decideConfigFate(TFI_t dbfi, const int dbix,
|
||||||
const char * baseName, short dbMode,
|
TFI_t newfi, const int newix, rpmtransFlags transFlags)
|
||||||
const char * dbMd5, const char * dbLink, short newMode,
|
|
||||||
const char * newMd5, const char * newLink, int newFlags,
|
|
||||||
rpmtransFlags transFlags)
|
|
||||||
/*@*/
|
/*@*/
|
||||||
{
|
{
|
||||||
char buffer[1024];
|
const char *dirName = newfi->dnl[newfi->dil[newix]];
|
||||||
const char * dbAttr, * newAttr;
|
const char *baseName = newfi->bnl[newix];
|
||||||
fileTypes dbWhat, newWhat, diskWhat;
|
|
||||||
struct stat sb;
|
|
||||||
int i, rc;
|
|
||||||
int save = (newFlags & RPMFILE_NOREPLACE) ? FA_ALTNAME : FA_SAVE;
|
|
||||||
char * filespec = alloca(strlen(dirName) + strlen(baseName) + 1);
|
char * filespec = alloca(strlen(dirName) + strlen(baseName) + 1);
|
||||||
|
|
||||||
(void) stpcpy( stpcpy(filespec, dirName), baseName);
|
(void) stpcpy( stpcpy(filespec, dirName), baseName);
|
||||||
|
|
||||||
|
struct stat sb;
|
||||||
if (lstat(filespec, &sb)) {
|
if (lstat(filespec, &sb)) {
|
||||||
/*
|
/*
|
||||||
* The file doesn't exist on the disk. Create it unless the new
|
* The file doesn't exist on the disk. Create it unless the new
|
||||||
* package has marked it as missingok, or allfiles is requested.
|
* package has marked it as missingok, or allfiles is requested.
|
||||||
*/
|
*/
|
||||||
if (!(transFlags & RPMTRANS_FLAG_ALLFILES) &&
|
if (!(transFlags & RPMTRANS_FLAG_ALLFILES) &&
|
||||||
(newFlags & RPMFILE_MISSINGOK)) {
|
(newfi->fflags[newix] & RPMFILE_MISSINGOK)) {
|
||||||
rpmMessage(RPMMESS_DEBUG, _("%s skipped due to missingok flag\n"),
|
rpmMessage(RPMMESS_DEBUG, _("%s skipped due to missingok flag\n"),
|
||||||
filespec);
|
filespec);
|
||||||
return FA_SKIP;
|
return FA_SKIP;
|
||||||
@ -814,43 +807,44 @@ static fileAction decideFileFate(const char * dirName,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
diskWhat = whatis(sb.st_mode);
|
fileTypes diskWhat = whatis(sb.st_mode);
|
||||||
dbWhat = whatis(dbMode);
|
fileTypes dbWhat = whatis(dbfi->fmodes[dbix]);
|
||||||
newWhat = whatis(newMode);
|
fileTypes newWhat = whatis(newfi->fmodes[newix]);
|
||||||
|
|
||||||
/* RPM >= 2.3.10 shouldn't create config directories -- we'll ignore
|
/* RPM >= 2.3.10 shouldn't create config directories -- we'll ignore
|
||||||
them in older packages as well */
|
them in older packages as well */
|
||||||
if (newWhat == XDIR) {
|
if (newWhat == XDIR)
|
||||||
return FA_CREATE;
|
return FA_CREATE;
|
||||||
}
|
|
||||||
|
|
||||||
if (diskWhat != newWhat) {
|
fileAction save = (newfi->fflags[newix] & RPMFILE_NOREPLACE) ? FA_ALTNAME : FA_SAVE;
|
||||||
|
if (diskWhat != newWhat)
|
||||||
return save;
|
return save;
|
||||||
} else if (newWhat != dbWhat && diskWhat != dbWhat) {
|
else if (newWhat != dbWhat && diskWhat != dbWhat)
|
||||||
return save;
|
return save;
|
||||||
} else if (dbWhat != newWhat) {
|
else if (dbWhat != newWhat)
|
||||||
return FA_CREATE;
|
return FA_CREATE;
|
||||||
} else if (dbWhat != LINK && dbWhat != REG) {
|
else if (dbWhat != LINK && dbWhat != REG)
|
||||||
return FA_CREATE;
|
return FA_CREATE;
|
||||||
}
|
|
||||||
|
|
||||||
|
const char *dbAttr, *newAttr;
|
||||||
|
char buffer[1024];
|
||||||
if (dbWhat == REG) {
|
if (dbWhat == REG) {
|
||||||
rc = domd5(filespec, buffer, 1);
|
int rc = mdfile(filespec, buffer);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
/* assume the file has been removed, don't freak */
|
/* assume the file has been removed, don't freak */
|
||||||
return FA_CREATE;
|
return FA_CREATE;
|
||||||
}
|
}
|
||||||
dbAttr = dbMd5;
|
dbAttr = dbfi->fmd5s[dbix];
|
||||||
newAttr = newMd5;
|
newAttr = newfi->fmd5s[newix];
|
||||||
} else /* dbWhat == LINK */ {
|
} else /* dbWhat == LINK */ {
|
||||||
memset(buffer, 0, sizeof(buffer));
|
memset(buffer, 0, sizeof(buffer));
|
||||||
i = readlink(filespec, buffer, sizeof(buffer) - 1);
|
ssize_t len = readlink(filespec, buffer, sizeof(buffer) - 1);
|
||||||
if (i == -1) {
|
if (len < 0) {
|
||||||
/* assume the file has been removed, don't freak */
|
/* assume the file has been removed, don't freak */
|
||||||
return FA_CREATE;
|
return FA_CREATE;
|
||||||
}
|
}
|
||||||
dbAttr = dbLink;
|
dbAttr = dbfi->flinks[dbix];
|
||||||
newAttr = newLink;
|
newAttr = newfi->flinks[newix];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this order matters - we'd prefer to CREATE the file if at all
|
/* this order matters - we'd prefer to CREATE the file if at all
|
||||||
@ -967,19 +961,8 @@ static int handleInstInstalledFiles(const TFI_t fi, /*@null@*/ rpmdb db,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isCfgFile) {
|
if (isCfgFile)
|
||||||
fi->actions[fileNum] = decideFileFate(
|
fi->actions[fileNum] = decideConfigFate(otherFi, otherFileNum, fi, fileNum, transFlags);
|
||||||
fi->dnl[fi->dil[fileNum]],
|
|
||||||
fi->bnl[fileNum],
|
|
||||||
otherFi->fmodes[otherFileNum],
|
|
||||||
otherFi->fmd5s[otherFileNum],
|
|
||||||
otherFi->flinks[otherFileNum],
|
|
||||||
fi->fmodes[fileNum],
|
|
||||||
fi->fmd5s[fileNum],
|
|
||||||
fi->flinks[fileNum],
|
|
||||||
fi->fflags[fileNum],
|
|
||||||
transFlags);
|
|
||||||
}
|
|
||||||
|
|
||||||
fi->replacedSizes[fileNum] = otherFi->fsizes[otherFileNum];
|
fi->replacedSizes[fileNum] = otherFi->fsizes[otherFileNum];
|
||||||
}
|
}
|
||||||
|
@ -31,8 +31,6 @@ extern int _rpmio_debug;
|
|||||||
#define PyObject_HEAD int _PyObjectHead
|
#define PyObject_HEAD int _PyObjectHead
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern int mdfile(const char *fn, unsigned char *digest);
|
|
||||||
|
|
||||||
void initrpm(void);
|
void initrpm(void);
|
||||||
|
|
||||||
/* from lib/misc.c */
|
/* from lib/misc.c */
|
||||||
|
Loading…
Reference in New Issue
Block a user