summaryrefslogtreecommitdiff
path: root/build
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2012-08-01 16:38:15 +0300
committerPanu Matilainen <pmatilai@redhat.com>2012-08-01 16:38:15 +0300
commit94b4ee60c00b6cf8c65dd29e6bd4c0e3177a33b3 (patch)
treebf1f31dbf7df27ed612dcaf712d45368688e94fb /build
parentd6775a746bbaf8ddc8a91c9fae68ae91af1cc570 (diff)
downloadlibrpm-tizen-94b4ee60c00b6cf8c65dd29e6bd4c0e3177a33b3.tar.gz
librpm-tizen-94b4ee60c00b6cf8c65dd29e6bd4c0e3177a33b3.tar.bz2
librpm-tizen-94b4ee60c00b6cf8c65dd29e6bd4c0e3177a33b3.zip
Refactor the struct stat hacking into a helper function
- Shouldn't change actual functionality, just makes the code easier to read and fit on screen by reducing indentation level. - Add further commentary about what it does and why.
Diffstat (limited to 'build')
-rw-r--r--build/files.c84
1 files changed, 46 insertions, 38 deletions
diff --git a/build/files.c b/build/files.c
index 1cfe7c4d4..dd1136ed0 100644
--- a/build/files.c
+++ b/build/files.c
@@ -1254,6 +1254,30 @@ static void FileListFree(FileList fl)
/* forward ref */
static rpmRC recurseDir(FileList fl, const char * diskPath);
+/* Hack up a stat structure for a %dev or non-existing %ghost */
+static struct stat * fakeStat(FileEntry cur, struct stat * statp)
+{
+ time_t now = time(NULL);
+
+ if (cur->devtype) {
+ statp->st_rdev = ((cur->devmajor & 0xff) << 8) | (cur->devminor & 0xff);
+ statp->st_dev = statp->st_rdev;
+ statp->st_mode = (cur->devtype == 'b' ? S_IFBLK : S_IFCHR);
+ } else {
+ /* non-existing %ghost file or directory */
+ statp->st_mode = cur->isDir ? S_IFDIR : S_IFREG;
+ /* can't recurse into non-existing directory */
+ if (cur->isDir)
+ cur->isDir = 1;
+ }
+ statp->st_mode |= (cur->ar.ar_fmode & 0777);
+ statp->st_atime = now;
+ statp->st_mtime = now;
+ statp->st_ctime = now;
+ statp->st_nlink = 1;
+ return statp;
+}
+
/**
* Add a file to the package manifest.
* @param fl package file tree walk data
@@ -1301,48 +1325,32 @@ static rpmRC addFile(FileList fl, const char * diskPath,
if (*cpioPath == '\0')
cpioPath = "/";
+ /*
+ * Unless recursing, we dont have stat() info at hand. Handle the
+ * various cases, preserving historical behavior wrt %dev():
+ * - for %dev() entries we fake it up whether the file exists or not
+ * - otherwise try to grab the data by lstat()
+ * - %ghost entries might not exist, fake it up
+ */
if (statp == NULL) {
- time_t now = time(NULL);
- statp = &statbuf;
- memset(statp, 0, sizeof(*statp));
+ memset(&statbuf, 0, sizeof(statbuf));
+
if (fl->cur.devtype) {
- /* XXX hack up a stat structure for a %dev(...) directive. */
- statp->st_nlink = 1;
- statp->st_rdev =
- ((fl->cur.devmajor & 0xff) << 8) | (fl->cur.devminor & 0xff);
- statp->st_dev = statp->st_rdev;
- statp->st_mode = (fl->cur.devtype == 'b' ? S_IFBLK : S_IFCHR);
- statp->st_mode |= (fl->cur.ar.ar_fmode & 0777);
- statp->st_atime = now;
- statp->st_mtime = now;
- statp->st_ctime = now;
+ statp = fakeStat(&(fl->cur), &statbuf);
+ } else if (lstat(diskPath, &statbuf) == 0) {
+ statp = &statbuf;
+ } else if (fl->cur.attrFlags & RPMFILE_GHOST) {
+ statp = fakeStat(&(fl->cur), &statbuf);
} else {
- int is_ghost = fl->cur.attrFlags & RPMFILE_GHOST;
-
- if (lstat(diskPath, statp)) {
- if (is_ghost) {
- /* non-existing %ghost file or directory */
- statp->st_mode = fl->cur.isDir ? S_IFDIR : S_IFREG;
- statp->st_mode |= (fl->cur.ar.ar_fmode & 0777);
- statp->st_atime = now;
- statp->st_mtime = now;
- statp->st_ctime = now;
- /* can't recurse into non-existing directory */
- if (fl->cur.isDir)
- fl->cur.isDir = 1;
- } else {
- int lvl = RPMLOG_ERR;
- const char *msg = fl->cur.isDir ?
- _("Directory not found: %s\n") :
- _("File not found: %s\n");
- if (fl->cur.attrFlags & RPMFILE_EXCLUDE) {
- lvl = RPMLOG_WARNING;
- rc = RPMRC_OK;
- }
- rpmlog(lvl, msg, diskPath);
- goto exit;
- }
+ int lvl = RPMLOG_ERR;
+ const char *msg = fl->cur.isDir ? _("Directory not found: %s\n") :
+ _("File not found: %s\n");
+ if (fl->cur.attrFlags & RPMFILE_EXCLUDE) {
+ lvl = RPMLOG_WARNING;
+ rc = RPMRC_OK;
}
+ rpmlog(lvl, msg, diskPath);
+ goto exit;
}
}