Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Allow pkg_set_from_file to trimcr, this allows pkg convert to 100% work
Baptiste Daroussin committed 13 years ago
commit 83736789ab2ed5480435beb3e21ab08ceaef2fce
parent af3594e
6 files changed +16 -13
modified libpkg/pkg.c
@@ -358,7 +358,7 @@ pkg_set_mtree(struct pkg *pkg, const char *mtree) {


int
-
pkg_set_from_file(struct pkg *pkg, pkg_attr attr, const char *path)
+
pkg_set_from_file(struct pkg *pkg, pkg_attr attr, const char *path, bool trimcr)
{
	char *buf = NULL;
	off_t size = 0;
@@ -370,6 +370,9 @@ pkg_set_from_file(struct pkg *pkg, pkg_attr attr, const char *path)
	if ((ret = file_to_buffer(path, &buf, &size)) !=  EPKG_OK)
		return (ret);

+
	while (trimcr && buf[strlen(buf) - 1] == '\n')
+
		buf[strlen(buf) - 1] = '\0';
+

	ret = pkg_set(pkg, attr, buf);

	free(buf);
modified libpkg/pkg.h.in
@@ -605,7 +605,7 @@ int pkgdb_file_set_cksum(struct pkgdb *db, struct pkg_file *file,
/**
 * Read the content of a file into a buffer, then call pkg_set().
 */
-
int pkg_set_from_file(struct pkg *pkg, pkg_attr attr, const char *file);
+
int pkg_set_from_file(struct pkg *pkg, pkg_attr attr, const char *file, bool trimcr);

/**
 * Allocate a new struct pkg and add it to the deps of pkg.
modified libpkg/pkg_create.c
@@ -242,7 +242,7 @@ pkg_create_staged(const char *outdir, pkg_formats format, const char *rootdir,
		if (snprintf(path, sizeof(path), "%s/+DESC", md_dir) == -1)
			goto cleanup;
		if (access(path, F_OK) == 0)
-
			pkg_set_from_file(pkg, PKG_DESC, path);
+
			pkg_set_from_file(pkg, PKG_DESC, path, false);
	}

	/* if no message try to get it from a file */
@@ -252,7 +252,7 @@ pkg_create_staged(const char *outdir, pkg_formats format, const char *rootdir,
		if (ret == -1)
			goto cleanup;
		if (access(path, F_OK) == 0)
-
			pkg_set_from_file(pkg, PKG_MESSAGE, path);
+
			pkg_set_from_file(pkg, PKG_MESSAGE, path, false);
	}

	/* if no arch autodetermine it */
@@ -269,7 +269,7 @@ pkg_create_staged(const char *outdir, pkg_formats format, const char *rootdir,
		if (ret == -1)
			goto cleanup;
		if (access(path, F_OK) == 0)
-
			pkg_set_from_file(pkg, PKG_MTREE, path);
+
			pkg_set_from_file(pkg, PKG_MTREE, path, false);
	}

	for (i = 0; scripts[i] != NULL; i++) {
modified libpkg/pkg_old.c
@@ -73,19 +73,19 @@ pkg_old_load_from_path(struct pkg *pkg, const char *path)

	snprintf(fpath, MAXPATHLEN, "%s/+COMMENT", path);
	if (access(fpath, F_OK) == 0)
-
		pkg_set_from_file(pkg, PKG_COMMENT, fpath);
+
		pkg_set_from_file(pkg, PKG_COMMENT, fpath, true);

	snprintf(fpath, sizeof(fpath), "%s/+DESC", path);
	if (access(fpath, F_OK) == 0)
-
		pkg_set_from_file(pkg, PKG_DESC, fpath);
+
		pkg_set_from_file(pkg, PKG_DESC, fpath, false);

	snprintf(fpath, sizeof(fpath), "%s/+DISPLAY", path);
	if (access(fpath, F_OK) == 0)
-
		pkg_set_from_file(pkg, PKG_MESSAGE, fpath);
+
		pkg_set_from_file(pkg, PKG_MESSAGE, fpath, false);

	snprintf(fpath, sizeof(fpath), "%s/+MTREE_DIRS", path);
	if (access(fpath, F_OK) == 0)
-
		pkg_set_from_file(pkg, PKG_MTREE, fpath);
+
		pkg_set_from_file(pkg, PKG_MTREE, fpath, false);

	for (i = 0; scripts[i] != NULL; i++) {
		snprintf(fpath, sizeof(fpath), "%s/%s", path, scripts[i]);
modified libpkg/pkg_ports.c
@@ -155,7 +155,7 @@ setprefix(struct plist *p, char *line, struct file_attr *a)
		p->prefix = line;

	pkg_get(p->pkg, PKG_PREFIX, &pkgprefix);
-
	if (pkgprefix == NULL)
+
	if (pkgprefix == NULL || *pkgprefix == '\0')
		pkg_set(p->pkg, PKG_PREFIX, line);

	p->slash = p->prefix[strlen(p->prefix) -1] == '/' ? "" : "/";
modified pkg/register.c
@@ -154,15 +154,15 @@ exec_register(int argc, char **argv)
	}

	snprintf(fpath, sizeof(fpath), "%s/+DESC", mdir);
-
	pkg_set_from_file(pkg, PKG_DESC, fpath);
+
	pkg_set_from_file(pkg, PKG_DESC, fpath, false);

	snprintf(fpath, sizeof(fpath), "%s/+DISPLAY", mdir);
	if (access(fpath, F_OK) == 0)
-
		 pkg_set_from_file(pkg, PKG_MESSAGE, fpath);
+
		 pkg_set_from_file(pkg, PKG_MESSAGE, fpath, false);

	snprintf(fpath, sizeof(fpath), "%s/+MTREE_DIRS", mdir);
	if (access(fpath, F_OK) == 0)
-
		pkg_set_from_file(pkg, PKG_MTREE, fpath);
+
		pkg_set_from_file(pkg, PKG_MTREE, fpath, false);

	for (i = 0; scripts[i] != NULL; i++) {
		snprintf(fpath, sizeof(fpath), "%s/%s", mdir, scripts[i]);