Radish alpha
H
HardenedBSD Package Manager
Radicle
Git (anonymous pull)
Log in to clone via SSH
Fix build on platforms without chflags and those without chflagsat
Baptiste Daroussin committed 11 years ago
commit 40de1c0465f9556cd12d957c8a67a191b723c3fd
parent f4f09f725f1127be0377290626ef1a5ad983b6d5
3 files changed +43 -4
modified configure.ac
@@ -329,6 +329,8 @@ if test "$ac_cv_func_dirname" = yes ; then
	AC_DEFINE(HAVE_BSD_DIRNAME, 1, [Define 1 if you have 'dirname(const char *)' function.])
fi

+
AC_CHECK_FUNCS(chflags chflagsat)
+

AC_CHECK_FUNCS(basename_r)
AC_CACHE_CHECK(for BSD basename(const char *),
               ac_cv_func_basename,
modified libpkg/pkg_add.c
@@ -257,9 +257,10 @@ do_extract(struct archive *a, struct archive_entry *ae, const char *location,

		/* Rename old file */
		if (renamed) {
-
			bool old = false;

			pkg_debug(1, "Renaming %s -> %s", rpath, pathname);
+
#ifdef HAVE_CHFLAGS
+
			bool old = false;
			if (aest->st_flags & NOCHANGESFLAGS)
				chflags(rpath, aest->st_flags & ~NOCHANGESFLAGS);

@@ -268,18 +269,23 @@ do_extract(struct archive *a, struct archive_entry *ae, const char *location,
				if (st.st_flags & NOCHANGESFLAGS)
					chflags(pathname, aest->st_flags & ~NOCHANGESFLAGS);
			}
+
#endif

			if (rename(rpath, pathname) == -1) {
+
#ifdef HAVE_CHFLAGS
				/* restore flags */
				if (old)
					chflags(pathname, st.st_flags);
+
#endif
				pkg_emit_error("cannot rename %s to %s: %s", rpath, pathname,
					strerror(errno));
				retcode = EPKG_FATAL;
				goto cleanup;
			}
+
#ifdef HAVE_CHFLAGS
			/* Restore flags on the final file */
			chflags(pathname, aest->st_flags);
+
#endif
		}

		if (string_end_with(pathname, ".pkgnew"))
@@ -300,8 +306,10 @@ cleanup:
	pkg_emit_extract_finished(pkg);

	if (renamed && retcode == EPKG_FATAL) {
+
#ifdef HAVE_CHFLAGS
		if (aest->st_flags & NOCHANGESFLAGS)
			chflags(rpath, aest->st_flags & ~NOCHANGESFLAGS);
+
#endif
		unlink(rpath);
	}

modified libpkg/pkg_delete.c
@@ -28,6 +28,10 @@
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

+
#ifdef HAVE_CONFIG_H
+
#include "pkg_config.h"
+
#endif
+

#include <assert.h>
#include <errno.h>
#include <string.h>
@@ -187,11 +191,24 @@ rmdir_p(struct pkgdb *db, struct pkg *pkg, char *dir, const char *prefix_r)
		return;

	pkg_debug(1, "removing directory %s", fullpath);
-
	if (fstatat(pkg->rootfd, dir, &st, AT_SYMLINK_NOFOLLOW) != -1)
+
#ifdef HAVE_CHFLAGS
+
	if (fstatat(pkg->rootfd, dir, &st, AT_SYMLINK_NOFOLLOW) != -1) {
		if (st.st_flags & NOCHANGESFLAGS)
+
#ifdef HAVE_CHFLAGSAT
			chflagsat(pkg->rootfd, dir,
			    st.st_flags & ~NOCHANGESFLAGS,
			    AT_SYMLINK_NOFOLLOW);
+
#else
+
			int fd;
+

+
			fd = openat(pkg->rootfd, dir, O_NOFOLLOW);
+
			if (fd > 0) {
+
				fchflags(fd, st.st_flags & ~NOCHANGESFLAGS);
+
				close(fd);
+
			}
+
#endif
+
	}
+
#endif

	if (unlinkat(pkg->rootfd, dir, AT_REMOVEDIR) == -1) {
		if (errno != ENOTEMPTY && errno != EBUSY)
@@ -276,12 +293,24 @@ pkg_delete_file(struct pkg *pkg, struct pkg_file *file, unsigned force)
		}
	}

-
	if (fstatat(pkg->rootfd, path, &st, AT_SYMLINK_NOFOLLOW) != -1)
+
#ifdef HAVE_CHFLAGS
+
	if (fstatat(pkg->rootfd, path, &st, AT_SYMLINK_NOFOLLOW) != -1) {
		if (st.st_flags & NOCHANGESFLAGS)
+
#ifdef HAVE_CHFLAGSAT
			chflagsat(pkg->rootfd, path,
			    st.st_flags & ~NOCHANGESFLAGS,
			    AT_SYMLINK_NOFOLLOW);
-

+
#else
+
			int fd;
+

+
			fd = openat(pkg->rootfd, path, O_NOFOLLOW);
+
			if (fd > 0) {
+
				fchflags(fd, st.st_flags & ~NOCHANGESFLAGS);
+
				close(fd);
+
			}
+
#endif
+
	}
+
#endif
	if (unlinkat(pkg->rootfd, path, 0) == -1) {
		if (force < 2)
			pkg_emit_errno("unlinkat", path);