Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Hudge simplification for config file management, no more need of @conf :) if a file ends with the .pkgconf extension it is a config file. for a file named file.pkgconf if file doesn't exists then pkg add will create both file.pkgconf and file TODO: purge option on delete to remove the left configuration files if any
Baptiste Daroussin committed 15 years ago
commit 2748cf7a32361408654600e5487a00ec9b6f6ae8
parent 0d72ef7
5 files changed +41 -51
modified libpkg/pkg_add.c
@@ -21,25 +21,30 @@ do_extract(struct archive *a, struct archive_entry *ae)
	int retcode = EPKG_OK;
	int ret = 0;
	char path[MAXPATHLEN];
-
	char *tmp;
	struct stat st;

	do {
-
		strlcpy(path, archive_entry_pathname(ae), MAXPATHLEN);
-
		if (fnmatch("*.pkgconf", path, 0) != FNM_NOMATCH) {
-
			tmp = strrchr(path, '.');
-
			tmp[0] = '\0';
-

-
			if (lstat(path, &st) != ENOENT)
-
				strlcat(path, ".pkgnew", MAXPATHLEN);
-

-
			archive_entry_set_pathname(ae, path);
-
		}
-

		if (archive_read_extract(a, ae, EXTRACT_ARCHIVE_FLAGS) != ARCHIVE_OK) {
			retcode = pkg_error_set(EPKG_FATAL, "%s", archive_error_string(a));
			break;
		}
+

+
		/*
+
		 * if the file is a configuration file and the configuration
+
		 * file does not already exist on the file system, then
+
		 * extract it
+
		 * ex: conf1.cfg.pkgconf:
+
		 * if conf1.cfg doesn't exists create it based on
+
		 * conf1.cfg.pkgconf
+
		 */
+
		if (is_conf_file(archive_entry_pathname(ae), path)
+
		    && lstat(path, &st) == ENOENT) {
+
			archive_entry_set_pathname(ae, path);
+
			if (archive_read_extract(a, ae, EXTRACT_ARCHIVE_FLAGS) != ARCHIVE_OK) {
+
				retcode = pkg_error_set(EPKG_FATAL, "%s", archive_error_string(a));
+
				break;
+
			}
+
		}
	} while ((ret = archive_read_next_header(a, &ae)) == ARCHIVE_OK);

	if (ret != ARCHIVE_EOF)
modified libpkg/pkg_create.c
@@ -8,8 +8,6 @@
#include <libgen.h>
#include <string.h>
#include <fcntl.h>
-
#include <fnmatch.h>
-
#include <errno.h>

#include "pkg.h"
#include "pkg_error.h"
@@ -22,13 +20,11 @@ pkg_create_from_dir(struct pkg *pkg, const char *root, struct packing *pkg_archi
{
	char fpath[MAXPATHLEN];
	char newpath[MAXPATHLEN];
-
	char pkgnewpath[MAXPATHLEN];
	struct pkg_file **files;
	struct pkg_script **scripts;
	char *m;
	int i;
	const char *scriptname = NULL;
-
	struct stat st;

	pkg_emit_manifest(pkg, &m);

@@ -76,28 +72,12 @@ pkg_create_from_dir(struct pkg *pkg, const char *root, struct packing *pkg_archi

	if ((files = pkg_files(pkg)) != NULL) {
		for (i = 0; files[i] != NULL; i++) {
-
			strlcpy(newpath, pkg_file_path(files[i]), MAXPATHLEN);
-

-
			/* remove .pkgconf from newpath if needed */
-
			if (fnmatch("*.pkgconf", newpath, 0) != FNM_NOMATCH) {
-
				m = strrchr(newpath, '.');
-
				m[0] = '\0';
-
			}

			if (root != NULL)
				snprintf(fpath, sizeof(MAXPATHLEN), "%s%s", root, newpath);
			else
				strlcpy(fpath, newpath, MAXPATHLEN);

-
			/* 
-
			 * if a .pkgnew file exists, it must be from the last
-
			 * install then let's take it for the package creation
-
			 */
-
			snprintf(pkgnewpath, MAXPATHLEN, "%s.pkgnew", fpath);
-

-
			if (lstat(pkgnewpath, &st) != ENOENT)
-
				strlcpy(fpath, pkgnewpath, MAXPATHLEN);
-

			packing_append_file(pkg_archive, fpath, pkg_file_path(files[i]));
		}
	}
modified libpkg/pkg_ports.c
@@ -98,25 +98,7 @@ ports_parse_plist(struct pkg *pkg, char *plist)

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

-
			} else if (STARTS_WITH(plist_p, "@conf ")) {
-
				buf = plist_p;
-

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

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

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

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

-
				ret += pkg_addfile(pkg, path, NULL);
-
			}else {
+
			} else {
				warnx("%s is deprecated, ignoring", plist_p);
			}
		} else if (strlen(plist_p) > 0){
modified libpkg/pkg_util.c
@@ -288,3 +288,24 @@ sha256_file(const char *path, char out[65])
	return (EPKG_OK);
}

+
int
+
is_conf_file(const char *path, char newpath[MAXPATHLEN])
+
{
+
	size_t n;
+
	char *p = NULL;
+

+
	n = strlen(path);
+

+
	if (n < 8)
+
		return (0);
+

+
	p = strrchr(path, '.');
+

+
	if (p != NULL && !strcmp(p, ".pkgconf")) {
+
		strlcpy(newpath, path, MAXPATHLEN);
+
		newpath[n - 8] = '\0';
+
		return (1);
+
	}
+

+
	return (0);
+
}
modified libpkg/pkg_util.h
@@ -3,6 +3,7 @@

#include <sys/types.h>
#include <sys/sbuf.h>
+
#include <sys/param.h>

#define ARRAY_INIT {0, 0, NULL}

@@ -29,6 +30,7 @@ int format_exec_cmd(char **, const char *, const char *, const char *);
int split_chr(char *, char);
int file_fetch(const char *, const char *);
int is_dir(const char *);
+
int is_conf_file(const char *path, char newpath[MAXPATHLEN]);

int sha256_file(const char *, char[65]);
void sha256_str(const char *, char[65]);