Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Replace an if block with a case statement and add an enum
Brad Davis committed 9 years ago
commit 32475fc26655aba2a16e19ef3b63ac9262402fd5
parent 97fc95f
3 files changed +25 -16
modified libpkg/metalog.c
@@ -53,24 +53,25 @@ metalog_add(int type, const char *path, const char *uname, const char *gname,
	}

	// directory
-
	if (type == 0) {
+
	switch (type) {
+
	case PKG_METALOG_DIR:
		fprintf(metalogfp,
		    "./%s type=dir uname=%s gname=%s mode=%3o\n",
		    path, uname, gname, mode);
-
	}
-
	// file
-
	else if (type == 1) {
+
		break;
+
	case PKG_METALOG_FILE:
		fprintf(metalogfp,
		    "./%s type=file uname=%s gname=%s mode=%3o\n",
		    path, uname, gname, mode);
-
	}
-
	// link
-
	else if (type == 2) {
+
		break;
+
	case PKG_METALOG_LINK:
		fprintf(metalogfp,
		    "./%s type=link uname=%s gname=%s mode=%3o link=%s\n",
		    path, uname, gname, mode, link);
+
		break;
	}

+

	return EPKG_OK;
}

modified libpkg/pkg_add.c
@@ -352,8 +352,9 @@ do_extract_dir(struct pkg* pkg, struct archive *a __unused, struct archive_entry
		}
	}

-
	if (metalog_add(0, RELATIVE_PATH(path), archive_entry_uname(ae),
-
	    archive_entry_gname(ae), aest->st_mode & ~S_IFDIR, NULL) != EPKG_OK) {
+
	if (metalog_add(PKG_METALOG_FILE, RELATIVE_PATH(path),
+
	    archive_entry_uname(ae), archive_entry_gname(ae),
+
	    aest->st_mode & ~S_IFDIR, NULL) != EPKG_OK) {
		if (st.st_uid == d->uid && st.st_gid == d->gid &&
		    (st.st_mode & S_IFMT) == (d->perm & S_IFMT)) {
			d->noattrs = true;
@@ -401,9 +402,9 @@ retry:

	fill_timespec_buf(aest, tspec);

-
	if (metalog_add(2, RELATIVE_PATH(path), archive_entry_uname(ae),
-
	    archive_entry_gname(ae), aest->st_mode & ~S_IFLNK,
-
	    archive_entry_symlink(ae)) != EPKG_OK) {
+
	if (metalog_add(PKG_METALOG_LINK, RELATIVE_PATH(path),
+
	    archive_entry_uname(ae), archive_entry_gname(ae),
+
	    aest->st_mode & ~S_IFLNK, archive_entry_symlink(ae)) != EPKG_OK) {
		if (set_attrs(pkg->rootfd, f->temppath, aest->st_mode,
		    get_uid_from_archive(ae), get_gid_from_archive(ae),
		    &tspec[0], &tspec[1]) != EPKG_OK) {
@@ -438,8 +439,9 @@ do_extract_hardlink(struct pkg *pkg, struct archive *a __unused, struct archive_

	pkg_hidden_tempfile(f->temppath, sizeof(f->temppath), path);
	aest = archive_entry_stat(ae);
-
	metalog_add(1, RELATIVE_PATH(path), archive_entry_uname(ae),
-
	    archive_entry_gname(ae), aest->st_mode & ~S_IFREG, NULL);
+
	metalog_add(PKG_METALOG_FILE, RELATIVE_PATH(path),
+
	    archive_entry_uname(ae), archive_entry_gname(ae),
+
	    aest->st_mode & ~S_IFREG, NULL);

retry:
	if (linkat(pkg->rootfd, RELATIVE_PATH(fh->temppath),
@@ -531,8 +533,9 @@ retry:

	fill_timespec_buf(aest, tspec);

-
	if (metalog_add(1, RELATIVE_PATH(path), archive_entry_uname(ae),
-
	    archive_entry_gname(ae), aest->st_mode & ~S_IFREG, NULL) != EPKG_OK) {
+
	if (metalog_add(PKG_METALOG_FILE, RELATIVE_PATH(path),
+
	    archive_entry_uname(ae), archive_entry_gname(ae),
+
	    aest->st_mode & ~S_IFREG, NULL) != EPKG_OK) {
		if (set_attrs(pkg->rootfd, f->temppath, aest->st_mode,
		    get_uid_from_archive(ae), get_gid_from_archive(ae),
		    &tspec[0], &tspec[1]) != EPKG_OK)
modified libpkg/private/pkg.h
@@ -798,5 +798,10 @@ int metalog_open(const char *metalog);
int metalog_add(int type, const char *path, const char *uname,
    const char *gname, int mode, const char *link);
void metalog_close();
+
enum pkg_metalog_type {
+
	PKG_METALOG_FILE = 0,
+
	PKG_METALOG_DIR,
+
	PKG_METALOG_LINK,
+
};

#endif