Radish alpha
H
HardenedBSD Package Manager
Radicle
Git (anonymous pull)
Log in to clone via SSH
Do not try to set attributes and owners on already existing directories having the proper attributes and ownership already
Baptiste Daroussin committed 10 years ago
commit 8ce77aa6ba267174125014fc4eb8af217e95f441
parent a84f0fc8b04c3e8240a2343306dbdf3194c5d061
2 files changed +17 -7
modified libpkg/pkg_add.c
@@ -184,7 +184,7 @@ get_gid_from_archive(struct archive_entry *ae)

static int
set_attrs(int fd, char *path, mode_t perm, uid_t uid, gid_t gid,
-
    const struct timespec *ats, const struct timespec *mts, bool timefail)
+
    const struct timespec *ats, const struct timespec *mts)
{

#ifdef HAVE_UTIMENSAT
@@ -193,7 +193,7 @@ set_attrs(int fd, char *path, mode_t perm, uid_t uid, gid_t gid,
	times[0] = *ats;
	times[1] = *mts;
	if (utimensat(fd, RELATIVE_PATH(path), times,
-
	    AT_SYMLINK_NOFOLLOW) == -1 && timefail){
+
	    AT_SYMLINK_NOFOLLOW) == -1){
		pkg_emit_error("Fail to set time on %s: %s", path,
		    strerror(errno));
		return (EPKG_FATAL);
@@ -210,7 +210,7 @@ set_attrs(int fd, char *path, mode_t perm, uid_t uid, gid_t gid,
	if (getcwd(saved_cwd, sizeof(saved_cwd)) == NULL)
		saved_cwd[0] = '\0';
	fchdir(fd);
-
	if (lutimes(RELATIVE_PATH(path), &tv) == -1 && timefail) {
+
	if (lutimes(RELATIVE_PATH(path), &tv) == -1) {
		pkg_emit_error("Fail to set time on %s: %s", path,
		    strerror(errno));
		return (EPKG_FATAL);
@@ -240,6 +240,7 @@ do_extract_dir(struct pkg* pkg, struct archive *a __unused, struct archive_entry
{
	struct pkg_dir *d;
	const struct stat *aest;
+
	struct stat st;
	unsigned long clear;

	d = pkg_get_dir(pkg, path);
@@ -259,6 +260,12 @@ do_extract_dir(struct pkg* pkg, struct archive *a __unused, struct archive_entry

	if (!mkdirat_p(pkg->rootfd, path))
		return (EPKG_FATAL);
+
	if (fstatat(pkg->rootfd, path, &st, 0) == -1)
+
		return (EPKG_FATAL);
+
	if (st.st_uid == d->uid && st.st_gid == d->gid &&
+
	    (st.st_mode & S_IFMT) == (d->perm & S_IFMT)) {
+
		d->noattrs = true;
+
	}

	return (EPKG_OK);
}
@@ -295,7 +302,7 @@ do_extract_symlink(struct pkg *pkg, struct archive *a __unused, struct archive_e

	if (set_attrs(pkg->rootfd, f->temppath, aest->st_mode,
	    get_uid_from_archive(ae), get_gid_from_archive(ae),
-
	    &aest->st_atim, &aest->st_mtim, true) != EPKG_OK) {
+
	    &aest->st_atim, &aest->st_mtim) != EPKG_OK) {
		return (EPKG_FATAL);
	}
	return (EPKG_OK);
@@ -409,7 +416,7 @@ do_extract_regfile(struct pkg *pkg, struct archive *a, struct archive_entry *ae,

	if (set_attrs(pkg->rootfd, f->temppath, aest->st_mode,
	    get_uid_from_archive(ae), get_gid_from_archive(ae),
-
	    &aest->st_atim, &aest->st_mtim, true) != EPKG_OK)
+
	    &aest->st_atim, &aest->st_mtim) != EPKG_OK)
		return (EPKG_FATAL);
	return (EPKG_OK);
}
@@ -559,8 +566,10 @@ pkg_extract_finalize(struct pkg *pkg)
	}

	while (pkg_dirs(pkg, &d) == EPKG_OK) {
-
		if (set_attrs(pkg->rootfd, d->path, d->perm, d->uid, d->gid,
-
		    &d->time[0], &d->time[1], false) != EPKG_OK)
+
		if (d->noattrs)
+
			continue;
+
		if (set_attrs(pkg->rootfd, d->path, d->perm,
+
		    d->uid, d->gid, &d->time[0], &d->time[1]) != EPKG_OK)
			return (EPKG_FATAL);
	}

modified libpkg/private/pkg.h
@@ -357,6 +357,7 @@ struct pkg_dir {
	u_long		 fflags;
	uid_t		 uid;
	gid_t		 gid;
+
	bool		 noattrs;
	struct timespec	 time[2];
	struct pkg_dir	*prev;
	struct pkg_dir	*next;