Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Accept directories from plist for compatibility reasons, @dirrm and @dirrmtry are automatically changed to simple directory only directories listed in plist are removed during the pkg delete phase This also bring a feature: no more need for @exec mkdir to package empty directories \o/
Baptiste Daroussin committed 15 years ago
commit 7e2554eb5bb7bc2cab78e381daa31fc3d9ae721b
parent efe329e
4 files changed +34 -59
modified libpkg/pkg_delete.c
@@ -1,26 +1,12 @@
#include <string.h>
#include <err.h>
#include <unistd.h>
-
#include <search.h>
-
#include <archive.h>
-
#include <archive_entry.h>
#include <stdlib.h>

#include "pkg.h"
#include "pkg_error.h"
#include "pkg_util.h"

-
static
-
int
-
dircmp(char const * const path, struct array *a)
-
{
-
	for (size_t i = 0; i < a->len; i++)
-
		if (strcmp(path, a->data[i]) == 0)
-
			return (1);
-

-
	return (0);
-
}
-

int
pkg_delete(struct pkg *pkg, struct pkgdb *db, int force)
{
@@ -29,12 +15,7 @@ pkg_delete(struct pkg *pkg, struct pkgdb *db, int force)
	struct pkg_exec **execs;
	struct pkg_script **scripts;
	char sha256[65];
-
	const char *mtree = NULL;
-
	struct archive *a;
-
	struct archive_entry *ae;
-
	struct array mtreedirs = ARRAY_INIT;
	const char *prefix;
-
	char *path, *end, *fullpath;
	struct sbuf *script_cmd;
	int ret, i;

@@ -90,24 +71,6 @@ pkg_delete(struct pkg *pkg, struct pkgdb *db, int force)
		}
	}

-
	a = archive_read_new();
-
	archive_read_support_compression_none(a);
-
	archive_read_support_format_mtree(a);
-

-
	mtree = pkg_get(pkg, PKG_MTREE);
-
	if (archive_read_open_memory(a, strdup(mtree), strlen(mtree)) != ARCHIVE_OK)
-
		return (pkg_error_set(EPKG_FATAL, "mtree: %s", archive_error_string(a)));
-

-
	array_init(&mtreedirs, 20);
-

-
	while ((ret = archive_read_next_header(a, &ae)) == ARCHIVE_OK)
-
		array_append(&mtreedirs, strdup(archive_entry_pathname(ae)));
-

-
	if (ret != ARCHIVE_EOF) {
-
		array_free(&mtreedirs, &free);
-
		return (pkg_error_set(EPKG_FATAL, "%s", archive_error_string(a)));
-
	}
-

	for (i = 0; files[i] != NULL; i++) {
		/* check sha256 */
		if (pkg_file_sha256(files[i])[0] != '\0' &&
@@ -117,28 +80,14 @@ pkg_delete(struct pkg *pkg, struct pkgdb *db, int force)
					pkg_file_path(files[i]));

		else if (unlink(pkg_file_path(files[i])) == -1) {
-
			warn("unlink(%s)", pkg_file_path(files[i]));
-
			continue;
-
		} else {
-
			/* only delete directories that are in prefix */
-
			if (STARTS_WITH(pkg_file_path(files[i]), prefix)) {
-
				path = strdup(pkg_file_path(files[i]));
-
				fullpath = path;
-
				path += strlen(prefix) + 1;
-

-
				if (path[0] == '/')
-
					path++;
-

-
				while ((end = strrchr(path, '/')) != NULL) {
-
					end[0] = '\0';
-
					if (!dircmp(path, &mtreedirs))
-
						rmdir(fullpath);
-
				}
-
				free(fullpath);
+
			if (is_dir(pkg_file_path(files[i]))) {
+
				rmdir(pkg_file_path(files[i]));
+
			} else {
+
				warn("unlink(%s)", pkg_file_path(files[i]));
+
				continue;
			}
		}
	}
-
	array_free(&mtreedirs, &free);

	for (i = 0; scripts[i] != NULL; i++) {
		switch (pkg_script_type(scripts[i])) {
modified libpkg/pkg_ports.c
@@ -58,7 +58,7 @@ ports_parse_plist(struct pkg *pkg, char *plist)
					prefix = buf;
			} else if (STARTS_WITH(plist_p, "@comment ")){
				/* DO NOTHING: ignore the comments */
-
			} else if (STARTS_WITH(plist_p, "@unexec ") || STARTS_WITH(plist_p, "@exec")) {
+
			} else if (STARTS_WITH(plist_p, "@unexec ") || STARTS_WITH(plist_p, "@exec ")) {
				buf = plist_p;

				while (!isspace(buf[0]))
@@ -77,6 +77,27 @@ ports_parse_plist(struct pkg *pkg, char *plist)

				free(cmd);

+
			} else if (STARTS_WITH(plist_p, "@dirrm ") || STARTS_WITH(plist_p, "@dirrmtry ")) {
+

+
				buf = plist_p;
+

+
				/* remove the @dirrm or @dirrmtry */
+
				while (!isspace(buf[0]))
+
					buf++;
+

+
				while (isspace(buf[0]))
+
					buf++;
+

+
				if (prefix[strlen(prefix) -1 ] == '/')
+
					snprintf(path, MAXPATHLEN, "%s%s", prefix, buf);
+
				else
+
					snprintf(path, MAXPATHLEN, "%s/%s", prefix, buf);
+

+
				if (lstat(path, &st) >= 0)
+
					flatsize += st.st_size;
+

+
				ret += pkg_addfile(pkg, path, NULL);
+

			}else {
				warnx("%s is deprecated, ignoring", plist_p);
			}
@@ -90,7 +111,7 @@ ports_parse_plist(struct pkg *pkg, char *plist)
				snprintf(path, MAXPATHLEN, "%s/%s", prefix, buf);

			if (lstat(path, &st) >= 0) {
-
				if (!S_ISLNK(st.st_mode) && sha256_file(path, sha256) == 0)
+
				if (!S_ISLNK(st.st_mode) && !S_ISDIR(st.st_mode) && sha256_file(path, sha256) == 0)
					p = sha256;

				flatsize += st.st_size;
modified libpkg/pkgdb.c
@@ -581,7 +581,8 @@ pkgdb_loadfiles(struct pkgdb *db, struct pkg *pkg)
	const char sql[] = ""
		"SELECT path, sha256 "
		"FROM files "
-
		"WHERE package_id = ?1;";
+
		"WHERE package_id = ?1 "
+
		"ORDER BY PATH DESC";

	if (pkg->type != PKG_INSTALLED)
		return (ERROR_BAD_ARG("pkg"));
modified ports/pkg2ng
@@ -41,6 +41,10 @@ do
			print $0 >> pfile
		} else if ( $0 ~ /^@unexec/) {
			print $0 >> pfile
+
		} else if ( $0 ~ /^@dirrm/) {
+
			print $0 >> pfile
+
		} else if ( $0 ~ /^@dirrmtry/) {
+
			print $0 >> pfile
		} else if ( $0 ~ /^@conflict/) {
			conflict=conflict" "$2
		} else if ( $0 ~ /^@cwd/) {