Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Merge pull request #133 from yuripankov/master
Baptiste Daroussin committed 14 years ago
commit dc3c8a63cbca41edbea60f7a1d5490c05aa5b890
parent c40b9f4
11 files changed +69 -59
modified libpkg/backup.c
@@ -33,12 +33,14 @@ pkgdb_dump(struct pkgdb *db, char *dest)
		pkg_emit_manifest(pkg, &m);
		sbuf_clear(path);
		sbuf_printf(path, "%s-%s.yaml", name, version);
-
		packing_append_buffer(pack, m, sbuf_data(path), strlen(m));
+
		sbuf_finish(path);
+
		packing_append_buffer(pack, m, sbuf_get(path), strlen(m));
		free(m);
		if (mtree != NULL) {
			sbuf_clear(path);
			sbuf_printf(path, "%s-%s.mtree", name, version);
-
			packing_append_buffer(pack, mtree, sbuf_data(path), strlen(mtree));
+
			sbuf_finish(path);
+
			packing_append_buffer(pack, mtree, sbuf_get(path), strlen(mtree));
		}
	}

modified libpkg/pkg.c
@@ -945,7 +945,7 @@ pkg_open2(struct pkg **pkg_p, struct archive **a, struct archive_entry **ae, con

			sbuf_finish(manifest);

-
			ret = pkg_parse_manifest(pkg, sbuf_data(manifest));
+
			ret = pkg_parse_manifest(pkg, sbuf_get(manifest));
			if (ret != EPKG_OK) {
				retcode = EPKG_FATAL;
				goto cleanup;
modified libpkg/pkg_manifest.c
@@ -306,9 +306,9 @@ parse_mapping(struct pkg *pkg, yaml_node_t *item, yaml_document_t *doc, int attr
				if (val->type == YAML_SCALAR_NODE && val->data.scalar.length > 0) {
					urldecode(key->data.scalar.value, &tmp);
					if (val->data.scalar.value[0] == 'y')
-
						pkg_adddir(pkg, sbuf_data(tmp), 1);
+
						pkg_adddir(pkg, sbuf_get(tmp), 1);
					else
-
						pkg_adddir(pkg, sbuf_data(tmp), 0);
+
						pkg_adddir(pkg, sbuf_get(tmp), 0);
				} else if (val->type == YAML_MAPPING_NODE) {
					pkg_set_dirs_from_node(pkg, val, doc, key->data.scalar.value);
				} else {
@@ -319,7 +319,7 @@ parse_mapping(struct pkg *pkg, yaml_node_t *item, yaml_document_t *doc, int attr
			case PKG_FILES:
				if (val->type == YAML_SCALAR_NODE && val->data.scalar.length > 0) {
					urldecode(key->data.scalar.value, &tmp);
-
					pkg_addfile(pkg, sbuf_data(tmp), val->data.scalar.length == 64 ? val->data.scalar.value : NULL);
+
					pkg_addfile(pkg, sbuf_get(tmp), val->data.scalar.length == 64 ? val->data.scalar.value : NULL);
				} else if (val->type == YAML_MAPPING_NODE)
					pkg_set_files_from_node(pkg, val, doc, key->data.scalar.value);
				else
@@ -362,7 +362,7 @@ parse_mapping(struct pkg *pkg, yaml_node_t *item, yaml_document_t *doc, int attr
				}

				urldecode(val->data.scalar.value, &tmp);
-
				pkg_addscript(pkg, sbuf_data(tmp), script_type);
+
				pkg_addscript(pkg, sbuf_get(tmp), script_type);
				break;
		}

@@ -702,7 +702,7 @@ pkg_emit_manifest(struct pkg *pkg, char **dest)
	snprintf(tmpbuf, BUFSIZ, "%" PRId64, flatsize);
	manifest_append_kv(mapping, "flatsize", tmpbuf);
	urlencode(desc, &tmpsbuf);
-
	manifest_append_kv_literal(mapping, "desc", sbuf_data(tmpsbuf));
+
	manifest_append_kv_literal(mapping, "desc", sbuf_get(tmpsbuf));

	while (pkg_deps(pkg, &dep) == EPKG_OK) {
		if (depsmap == -1) {
@@ -770,7 +770,7 @@ pkg_emit_manifest(struct pkg *pkg, char **dest)
					files);
		}
		urlencode(pkg_file_get(file, PKG_FILE_PATH), &tmpsbuf);
-
		manifest_append_kv(files, sbuf_data(tmpsbuf), pkg_file_get(file, PKG_FILE_SUM) && strlen(pkg_file_get(file, PKG_FILE_SUM)) > 0 ? pkg_file_get(file, PKG_FILE_SUM) : "-");
+
		manifest_append_kv(files, sbuf_get(tmpsbuf), pkg_file_get(file, PKG_FILE_SUM) && strlen(pkg_file_get(file, PKG_FILE_SUM)) > 0 ? pkg_file_get(file, PKG_FILE_SUM) : "-");
	}

	seq = -1;
@@ -782,7 +782,7 @@ pkg_emit_manifest(struct pkg *pkg, char **dest)
					dirs);
		}
		urlencode(pkg_dir_path(dir), &tmpsbuf);
-
		manifest_append_kv(dirs, sbuf_data(tmpsbuf), pkg_dir_try(dir) ? "y" : "n");
+
		manifest_append_kv(dirs, sbuf_get(tmpsbuf), pkg_dir_try(dir) ? "y" : "n");
	}

	while (pkg_scripts(pkg, &script) == EPKG_OK) {
@@ -822,11 +822,11 @@ pkg_emit_manifest(struct pkg *pkg, char **dest)
				break;
		}
		urlencode(pkg_script_data(script), &tmpsbuf);
-
		manifest_append_kv_literal(scripts, script_types, sbuf_data(tmpsbuf));
+
		manifest_append_kv_literal(scripts, script_types, sbuf_get(tmpsbuf));
	}
	if (message != NULL && *message != '\0') {
		urlencode(desc, &tmpsbuf);
-
		manifest_append_kv_literal(mapping, "message", sbuf_data(tmpsbuf));
+
		manifest_append_kv_literal(mapping, "message", sbuf_get(tmpsbuf));
	}

	if (!yaml_emitter_dump(&emitter, &doc))
@@ -834,7 +834,7 @@ pkg_emit_manifest(struct pkg *pkg, char **dest)

	sbuf_free(tmpsbuf);
	sbuf_finish(destbuf);
-
	*dest = strdup(sbuf_data(destbuf));
+
	*dest = strdup(sbuf_get(destbuf));
	sbuf_delete(destbuf);

	yaml_emitter_delete(&emitter);
modified libpkg/pkg_ports.c
@@ -665,7 +665,7 @@ flush_script_buffer(struct sbuf *buf, struct pkg *p, int type)
{
	if (sbuf_len(buf) > 0) {
		sbuf_finish(buf);
-
		pkg_appendscript(p, sbuf_data(buf), type);
+
		pkg_appendscript(p, sbuf_get(buf), type);
	}
	sbuf_delete(buf);
}
@@ -753,7 +753,8 @@ ports_parse_plist(struct pkg *pkg, char *plist)
		} else if ((len = strlen(plist_p)) > 0){
			if (sbuf_len(pplist.unexec_buf) > 0) {
				sbuf_finish(pplist.unexec_buf);
-
				pre_unexec_append(pplist.pre_deinstall_buf, sbuf_data(pplist.unexec_buf), "");
+
				pre_unexec_append(pplist.pre_deinstall_buf,
+
				    sbuf_get(pplist.unexec_buf), "");
				sbuf_reset(pplist.unexec_buf);
			}
			buf = plist_p;
modified libpkg/pkg_util.c
@@ -28,13 +28,15 @@ sbuf_set(struct sbuf **buf, const char *str)
	return (0);
}

-
const char *
+
char *
sbuf_get(struct sbuf *buf)
{
	if (buf == NULL)
		return (NULL);

-
	return sbuf_data(buf);
+
	assert((buf->s_flags & SBUF_FINISHED) == SBUF_FINISHED);
+

+
	return (buf->s_buf);
}

void
modified libpkg/pkg_util.h
@@ -13,7 +13,7 @@
	pkg_emit_error("sqlite: %s", sqlite3_errmsg(db))

int sbuf_set(struct sbuf **, const char *);
-
const char * sbuf_get(struct sbuf *);
+
char * sbuf_get(struct sbuf *);
void sbuf_reset(struct sbuf *);
void sbuf_free(struct sbuf *);

modified libpkg/pkgdb.c
@@ -2010,9 +2010,10 @@ pkgdb_query_installs(struct pkgdb *db, match_t match, int nbpkgs, char **pkgs, c
	sbuf_printf(sql, how, "origin");
	sbuf_cat(sql, " OR ");
	sbuf_printf(sql, how, "name || \"-\" || version");
+
	sbuf_finish(sql);

	for (i = 0; i < nbpkgs; i++) {
-
		if (sqlite3_prepare_v2(db->sqlite, sbuf_data(sql), -1, &stmt, NULL) != SQLITE_OK) {
+
		if (sqlite3_prepare_v2(db->sqlite, sbuf_get(sql), -1, &stmt, NULL) != SQLITE_OK) {
			ERROR_SQLITE(db->sqlite);
			return (NULL);
		}
@@ -2297,9 +2298,10 @@ pkgdb_query_delete(struct pkgdb *db, match_t match, int nbpkgs, char **pkgs, int
		sbuf_printf(sql, how, "p.origin");
		sbuf_cat(sql, " OR ");
		sbuf_printf(sql, how, "p.name || \"-\" || p.version");
+
		sbuf_finish(sql);

		for (i = 0; i < nbpkgs; i++) {
-
			if (sqlite3_prepare_v2(db->sqlite, sbuf_data(sql), -1, &stmt, NULL) != SQLITE_OK) {
+
			if (sqlite3_prepare_v2(db->sqlite, sbuf_get(sql), -1, &stmt, NULL) != SQLITE_OK) {
				ERROR_SQLITE(db->sqlite);
				return (NULL);
			}
@@ -2307,7 +2309,8 @@ pkgdb_query_delete(struct pkgdb *db, match_t match, int nbpkgs, char **pkgs, int
			while (sqlite3_step(stmt) != SQLITE_DONE);
		}
	} else {
-
		if (sqlite3_prepare_v2(db->sqlite, sbuf_data(sql), -1, &stmt, NULL) != SQLITE_OK) {
+
		sbuf_finish(sql);
+
		if (sqlite3_prepare_v2(db->sqlite, sbuf_get(sql), -1, &stmt, NULL) != SQLITE_OK) {
			ERROR_SQLITE(db->sqlite);
			return (NULL);
		}
@@ -2523,7 +2526,7 @@ pkgdb_integrity_append(struct pkgdb *db, struct pkg *p)
			}
			sqlite3_finalize(stmt_conflicts);
			sbuf_finish(conflictmsg);
-
			pkg_emit_error(sbuf_data(conflictmsg));
+
			pkg_emit_error(sbuf_get(conflictmsg));
			ret = EPKG_FATAL;
		}
		sqlite3_reset(stmt);
@@ -2596,7 +2599,7 @@ pkgdb_integrity_check(struct pkgdb *db)
		}
		sqlite3_finalize(stmt_conflicts);
		sbuf_finish(conflictmsg);
-
		pkg_emit_error(sbuf_data(conflictmsg));
+
		pkg_emit_error(sbuf_get(conflictmsg));
		ret = EPKG_FATAL;
	}

modified libpkg/scripts.c
@@ -53,7 +53,7 @@ pkg_script_run(struct pkg * const pkg, pkg_script_t type)
			sbuf_cat(script_cmd, "\n");
			sbuf_cat(script_cmd, pkg_script_data(script));
			sbuf_finish(script_cmd);
-
			system(sbuf_data(script_cmd));
+
			system(sbuf_get(script_cmd));
		}
	}

modified pkg/pkg-query.1
@@ -59,29 +59,29 @@ There are two type of keyword for the query format: the multiline and the normal
one. Only one type of multiline pattern is accepted for a given query.
.Ss Normal patterns:
.Bl -tag -width F1
-
.It Cm %n
+
.It Cm \&%n
Name of the matched package
-
.It Cm %v
+
.It Cm \&%v
Version of the matched package
-
.It Cm %o
+
.It Cm \&%o
Origin of the matched package
-
.It Cm %p
+
.It Cm \&%p
Prefix of the matched package
-
.It Cm %m
+
.It Cm \&%m
Maintainer of the matched package
-
.It Cm %c
+
.It Cm \&%c
Comment of the matched package
-
.It Cm %w
+
.It Cm \&%w
Home page of the matched package
-
.It Cm %l
+
.It Cm \&%l
license logic of the matched package - nothing for single, & for AND, and | for OR
-
.It Cm %sh
+
.It Cm \&%sh
The flat size in human readable format of the matched package
-
.It Cm %sb
+
.It Cm \&%sb
The flat size in bytes of the matched package
-
.It Cm %a
+
.It Cm \&%a
Returns 1 if the matched package is an orphan package and can be pkg-autoremove(1)'d, 0 otherwise
-
.It Cm %? Ns Op drCFIDLUG
+
.It Cm \&%? Ns Op drCFIDLUG
Returns 0 if the list is empty and 1 if the list has information to display
.Bl -tag -width indent
.It Cm d
@@ -106,7 +106,7 @@ for groups
.El
.Ss Multiline patterns:
.Bl -tag -width F1
-
.It Cm %d Ns Op nov
+
.It Cm \&%d Ns Op nov
Expands to the list of dependencies for the matched package, where
.Cm n
stands for the package name,
@@ -114,7 +114,7 @@ stands for the package name,
for the package origin, and
.Cm v
for the package version.
-
.It Cm %r Ns Op nov
+
.It Cm \&%r Ns Op nov
Expands to the list of reverse dependencies for the matched package, where
.Cm n
stands for the package name,
@@ -122,27 +122,27 @@ stands for the package name,
for the package origin, and
.Cm v
for the package version.
-
.It Cm %C
+
.It Cm \&%C
Expands to the list of categories the matched package belongs to.
-
.It Cm %F Ns Op ps
+
.It Cm \&%F Ns Op ps
Expands to the list of files of the matched package, where
.Cm p
stands for path, and
.Cm s
for sum.
-
.It Cm %O Ns Op kv
+
.It Cm \&%O Ns Op kv
Expands to the list of options of the matched package, where
.Cm k
stands for option key, and
.Cm v
for option value.
-
.It Cm %L
+
.It Cm \&%L
Expands to the list of license(s) for the matched package.
-
.It Cm %U
+
.It Cm \&%U
Expands to the list of users needed by the matched package.
-
.It Cm %G
+
.It Cm \&%G
Expands to the list of groups needed by the matched package.
-
.It Cm %S
+
.It Cm \&%S
Expands to the list of scripts for the matching packages - install, deinstall, etc.
.El
.Sh ENVIRONMENT
modified pkg/query.c
@@ -4,6 +4,7 @@
#include <inttypes.h>
#include <libutil.h>
#include <pkg.h>
+
#include <pkg_util.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -250,66 +251,66 @@ print_query(struct pkg *pkg, char *qstr, char multiline)
		case 'd':
			while (pkg_deps(pkg, &dep) == EPKG_OK) {
				format_str(pkg, output, qstr, dep);
-
				printf("%s\n", sbuf_data(output));
+
				printf("%s\n", sbuf_get(output));
				break;
		}
		case 'r':
			while (pkg_rdeps(pkg, &dep) == EPKG_OK) {
				format_str(pkg, output, qstr, dep);
-
				printf("%s\n", sbuf_data(output));
+
				printf("%s\n", sbuf_get(output));
			}
			break;
		case 'C':
			while (pkg_categories(pkg, &cat) == EPKG_OK) {
				format_str(pkg, output, qstr, cat);
-
				printf("%s\n", sbuf_data(output));
+
				printf("%s\n", sbuf_get(output));
			}
			break;
		case 'O':
			while (pkg_options(pkg, &option) == EPKG_OK) {
				format_str(pkg, output, qstr, option);
-
				printf("%s\n", sbuf_data(output));
+
				printf("%s\n", sbuf_get(output));
			}
			break;
		case 'F':
			while (pkg_files(pkg, &file) == EPKG_OK) {
				format_str(pkg, output, qstr, file);
-
				printf("%s\n", sbuf_data(output));
+
				printf("%s\n", sbuf_get(output));
			}
			break;
		case 'D':
			while (pkg_dirs(pkg, &dir) == EPKG_OK) {
				format_str(pkg, output, qstr, dir);
-
				printf("%s\n", sbuf_data(output));
+
				printf("%s\n", sbuf_get(output));
			}
			break;
		case 'L':
			while (pkg_licenses(pkg, &lic) == EPKG_OK) {
				format_str(pkg, output, qstr, lic);
-
				printf("%s\n", sbuf_data(output));
+
				printf("%s\n", sbuf_get(output));
			}
			break;
		case 'U':
			while (pkg_users(pkg, &user) == EPKG_OK) {
				format_str(pkg, output, qstr, user);
-
				printf("%s\n", sbuf_data(output));
+
				printf("%s\n", sbuf_get(output));
			}
			break;
		case 'G':
			while (pkg_users(pkg, &user) == EPKG_OK) {
				format_str(pkg, output, qstr, group);
-
				printf("%s\n", sbuf_data(output));
+
				printf("%s\n", sbuf_get(output));
			}
			break;
		case 'S':
			while (pkg_scripts(pkg, &scripts) == EPKG_OK) {
				format_str(pkg, output, qstr, scripts);
-
				printf("%s\n", sbuf_data(output));
+
				printf("%s\n", sbuf_get(output));
			}
			break;
		default:
			format_str(pkg, output, qstr, dep);
-
			printf("%s\n", sbuf_data(output));
+
			printf("%s\n", sbuf_get(output));
			break;
	}
	sbuf_delete(output);
modified pkg/version.c
@@ -6,6 +6,7 @@
#define _WITH_GETLINE
#include <err.h>
#include <pkg.h>
+
#include <pkg_util.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@ -314,8 +315,8 @@ exec_version(int argc, char **argv)
			pkg_get(pkg, PKG_ORIGIN, &origin);
			sbuf_printf(cmd, "make -C %s/%s -VPKGVERSION", portsdir, origin);
			sbuf_finish(cmd);
-
			if ((res = exec_buf(sbuf_data(cmd))) != NULL) {
-
				buf = sbuf_data(res);
+
			if ((res = exec_buf(sbuf_get(cmd))) != NULL) {
+
				buf = sbuf_get(res);
				while (*buf != '\0') {
					if (*buf == '\n') {
						*buf = '\0';
@@ -323,7 +324,7 @@ exec_version(int argc, char **argv)
					}
					buf++;
				}
-
				print_version(pkg, "port", sbuf_data(res), limchar, opt);
+
				print_version(pkg, "port", sbuf_get(res), limchar, opt);
				sbuf_delete(res);
			} else {
				print_version(pkg, NULL, NULL, limchar, opt);