Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Implement file listing: pkg info -l pkgname
Baptiste Daroussin committed 15 years ago
commit 2dadd7a619319c6c5325c45d20fd6ab449389919
parent c0ad2bf
7 files changed +48 -3
modified libpkg/pkg.c
@@ -47,6 +47,12 @@ pkg_rdep(struct pkg *pkg, struct pkg *rdep)
}

int
+
pkg_files(struct pkg *pkg, const char **path)
+
{
+
	return (pkgdb_query_files(pkg, path));
+
}
+

+
int
pkg_dep(struct pkg *pkg, struct pkg *dep)
{
	pkg_reset(dep);
@@ -82,6 +88,10 @@ pkg_reset(struct pkg *pkg)
		sqlite3_finalize(pkg->which_stmt);
		pkg->which_stmt = NULL;
	}
+
	if (pkg->files_stmt != NULL) {
+
		sqlite3_finalize(pkg->files_stmt);
+
		pkg->files_stmt = NULL;
+
	}
	if (pkg->m != NULL) {
		pkg_manifest_free(pkg->m);
		pkg->m = NULL;
modified libpkg/pkg.h
@@ -22,6 +22,7 @@ const char *pkg_desc(struct pkg *);
const char *pkg_origin(struct pkg *);
int pkg_dep(struct pkg *, struct pkg *);
int pkg_rdep(struct pkg *, struct pkg *);
+
int pkg_files(struct pkg *, const char **);

/* pkgdb */
int pkgdb_open(struct pkgdb **);
modified libpkg/pkg_private.h
@@ -15,6 +15,7 @@ struct pkg {
	sqlite3_stmt *deps_stmt;
	sqlite3_stmt *rdeps_stmt;
	sqlite3_stmt *which_stmt;
+
	sqlite3_stmt *files_stmt;
	struct pkg_manifest *m;
};

modified libpkg/pkgdb.c
@@ -128,7 +128,7 @@ pkgdb_init(sqlite3 *sdb)
		"name TEXT,"
		"version TEXT,"
		"comment TEXT,"
-
		"desc TEXT",
+
		"desc TEXT,"
		"automatic INTEGER"
	");"
	"CREATE TABLE options ("
@@ -414,6 +414,29 @@ pkgdb_query_rdep(struct pkg *pkg, struct pkg *rdep) {
	}
}

+
int
+
pkgdb_query_files(struct pkg *pkg, const char **path) {
+
	int retcode;
+

+
	if (pkg->files_stmt == NULL) {
+
		sqlite3_prepare(pkg->pdb->sqlite,
+
						"SELECT path from files where package_id = ?1;", -1, &pkg->files_stmt, NULL);
+
		sqlite3_bind_text(pkg->files_stmt, 1, pkg->origin, -1, SQLITE_STATIC);
+
	}
+

+
	retcode = sqlite3_step(pkg->files_stmt);
+
	if (retcode == SQLITE_ROW) {
+
		*path = sqlite3_column_text(pkg->files_stmt, 0);
+
		return (0);
+
	} else if (retcode == SQLITE_DONE) {
+
		sqlite3_reset(pkg->files_stmt);
+
		return (1);
+
	} else {
+
		return (-1);
+
	}
+

+
}
+

static void
pkgdb_stmt_to_pkg(sqlite3_stmt *stmt, struct pkg *pkg)
{
modified libpkg/pkgdb.h
@@ -12,6 +12,7 @@ struct pkgdb {

int pkgdb_query_dep(struct pkg *, struct pkg *);
int pkgdb_query_rdep(struct pkg *, struct pkg *);
+
int pkgdb_query_files(struct pkg *, const char **);
void pkgdb_set_error(struct pkgdb *, int, const char *, ...);

#endif
modified pkg/info.c
@@ -10,7 +10,6 @@
 * list of options
 * -s: show package size: TODO
 * -S <type> : show scripts, type can be pre-install etc: TODO
-
 * -l: list contents of a package
 * -w <filename>: (which) finds which package the filename belongs to:
 */

@@ -20,13 +19,14 @@ cmd_info(int argc, char **argv)
	struct pkgdb *db;
	struct pkg *pkg;
	struct pkg *dep;
+
	const char *path;
	unsigned char opt = 0;
	match_t match = MATCH_EXACT;
	char ch;
	int retcode = 0;

	/* TODO: exclusive opts ? */
-
	while ((ch = getopt(argc, argv, "egxXdr")) != -1) {
+
	while ((ch = getopt(argc, argv, "egxXdrl")) != -1) {
		switch (ch) {
			case 'e':
				opt |= INFO_EXISTS;
@@ -46,6 +46,9 @@ cmd_info(int argc, char **argv)
			case 'r':
				opt |= INFO_PRINT_RDEP;
				break;
+
			case 'l':
+
				opt |= INFO_LIST_FILES;
+
				break;
		}
	}
	argc -= optind;
@@ -85,6 +88,11 @@ cmd_info(int argc, char **argv)
				printf("%s-%s\n", pkg_name(dep), pkg_version(dep));
			}
			printf("\n");
+
		} else if (opt & INFO_LIST_FILES) {
+
			printf("%s-%s owns the following files:\n", pkg_name(pkg), pkg_version(pkg));
+
			while (pkg_files(pkg, &path) == 0) {
+
				printf("%s\n", path);
+
			}
		} else {
			printf("%s-%s: %s\n", pkg_name(pkg), pkg_version(pkg), pkg_comment(pkg));
		}
modified pkg/info.h
@@ -4,6 +4,7 @@
#define INFO_PRINT_DEP (1<<0)
#define INFO_PRINT_RDEP (1<<1)
#define INFO_EXISTS (1<<2)
+
#define INFO_LIST_FILES (1<<3)

int cmd_info(int argc, char **argv);
#endif