Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Do not fail if writting to the metalog file fails
Baptiste Daroussin committed 9 years ago
commit 91e54c04f484dd152843c8651ec2f1424865603b
parent c579412
3 files changed +47 -37
modified libpkg/metalog.c
@@ -26,6 +26,7 @@



+
#include <errno.h>
#include "pkg.h"
#include "private/pkg.h"
#include "private/event.h"
@@ -37,42 +38,49 @@ metalog_open(const char *metalog)
{
	metalogfp = fopen(metalog, "a");
	if (metalogfp == NULL) {
-
		pkg_emit_errno("Unable to open metalog: %s", metalog);
+
		pkg_emit_error("Unable to open metalog '%s': %s", metalog,
+
		    strerror(errno));
		return EPKG_FATAL;
	} 

	return EPKG_OK;
}

-
int
+
void
metalog_add(int type, const char *path, const char *uname, const char *gname,
    int mode, const char *link)
{
	if (metalogfp == NULL) {
-
		return EPKG_FATAL;
+
		return;
	}

	// directory
	switch (type) {
	case PKG_METALOG_DIR:
-
		fprintf(metalogfp,
+
		if (fprintf(metalogfp,
		    "./%s type=dir uname=%s gname=%s mode=%3o\n",
-
		    path, uname, gname, mode);
+
		    path, uname, gname, mode) < 0) {
+
			pkg_emit_error("Unable to write to the metalog: %s",
+
			    strerror(errno));
+
		}
		break;
	case PKG_METALOG_FILE:
-
		fprintf(metalogfp,
+
		if (fprintf(metalogfp,
		    "./%s type=file uname=%s gname=%s mode=%3o\n",
-
		    path, uname, gname, mode);
+
		    path, uname, gname, mode) < 0) {
+
			pkg_emit_error("Unable to write to the metalog: %s",
+
			    strerror(errno));
+
		}
		break;
	case PKG_METALOG_LINK:
-
		fprintf(metalogfp,
+
		if (fprintf(metalogfp,
		    "./%s type=link uname=%s gname=%s mode=%3o link=%s\n",
-
		    path, uname, gname, mode, link);
+
		    path, uname, gname, mode, link) < 0) {
+
			pkg_emit_error("Unable to write to the metalog: %s",
+
			    strerror(errno));
+
		}
		break;
	}
-

-

-
	return EPKG_OK;
}

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

-
	if (metalog_add(PKG_METALOG_DIR, 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;
-
		}
+
	if (st.st_uid == d->uid && st.st_gid == d->gid &&
+
	    (st.st_mode & S_IFMT) == (d->perm & S_IFMT)) {
+
		d->noattrs = true;
	}

+
	metalog_add(PKG_METALOG_DIR, RELATIVE_PATH(path),
+
	    archive_entry_uname(ae), archive_entry_gname(ae),
+
	    aest->st_mode & ~S_IFDIR, NULL);
+

	return (EPKG_OK);
}

@@ -402,16 +402,16 @@ retry:

	fill_timespec_buf(aest, tspec);

-
	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) {
-
			return (EPKG_FATAL);
-
		}
+
	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) {
+
		return (EPKG_FATAL);
	}

+
	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));
+

	return (EPKG_OK);
}

@@ -439,9 +439,6 @@ 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(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),
@@ -458,6 +455,10 @@ retry:
		return (EPKG_FATAL);
	}

+
	metalog_add(PKG_METALOG_FILE, RELATIVE_PATH(path),
+
	    archive_entry_uname(ae), archive_entry_gname(ae),
+
	    aest->st_mode & ~S_IFREG, NULL);
+

	return (EPKG_OK);
}

@@ -533,15 +534,16 @@ retry:

	fill_timespec_buf(aest, tspec);

-
	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,
+
	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)
			return (EPKG_FATAL);
-
		return (EPKG_OK);
-
	}
+

+
	metalog_add(PKG_METALOG_FILE, RELATIVE_PATH(path),
+
	    archive_entry_uname(ae), archive_entry_gname(ae),
+
	    aest->st_mode & ~S_IFREG, NULL);
+

+
	return (EPKG_OK);
}

static int
modified libpkg/private/pkg.h
@@ -795,7 +795,7 @@ ucl_object_t* pkg_message_to_ucl(const struct pkg *pkg);
char* pkg_message_to_str(struct pkg *pkg);

int metalog_open(const char *metalog);
-
int metalog_add(int type, const char *path, const char *uname,
+
void 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 {