Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Here are the missing files
Baptiste Daroussin committed 14 years ago
commit 05c7c959934488ec3d7ca05c0f5dd94432acb55a
parent 576f311
3 files changed +87 -0
added libpkg/dump.c
@@ -0,0 +1,39 @@
+
#include <string.h>
+

+
#include "pkg.h"
+
#include "pkg_private.h"
+
#include "pkg_event.h"
+

+
int
+
pkgdb_dump(struct pkgdb *db, char *dest)
+
{
+
	struct pkgdb_it *it;
+
	struct pkg *pkg;
+
	struct sbuf *path;
+
	struct packing *pack;
+
	char *m;
+
	int ret;
+
	int query_flags = PKG_LOAD_DEPS | PKG_LOAD_CONFLICTS | PKG_LOAD_FILES |
+
					  PKG_LOAD_DIRS | PKG_LOAD_SCRIPTS | PKG_LOAD_OPTIONS |
+
					  PKG_LOAD_MTREE;
+

+
	packing_init(&pack, dest ? dest : "./pkgdump", TXZ);
+

+
	path = sbuf_new_auto();
+
	if ((it = pkgdb_query(db, NULL, MATCH_ALL)) == NULL) {
+
		/* TODO handle errors */
+
		return (EPKG_FATAL);
+
	}
+

+
	while ((ret = pkgdb_it_next(it, &pkg, query_flags)) == EPKG_OK) {
+
		pkg_emit_manifest(pkg, &m);
+
		sbuf_clear(path);
+
		sbuf_printf(path, "%s-%s.yaml", pkg_get(pkg, PKG_NAME), pkg_get(pkg, PKG_VERSION));
+
		packing_append_buffer(pack, m, sbuf_data(path), strlen(m));
+
		free(m);
+
	}
+

+
	sbuf_delete(path);
+
	packing_finish(pack);
+
	return (EPKG_OK);
+
}
added pkg/backup.c
@@ -0,0 +1,42 @@
+
#include <pkg.h>
+

+
#include "backup.h"
+

+
void
+
usage_backup(void)
+
{
+
	fprintf(stderr, "usage: pkg backup -[d|r] dest\n");
+
	fprintf(stderr, "For more information see 'pkg help backup'.\n");
+
}
+

+
int
+
exec_backup(int argc, char **argv)
+
{
+
	struct pkgdb  *db;
+
	char *dest = NULL;
+

+
	if (argc < 1 || argc > 2 || argv[1][0] != '-') {
+
		usage_backup();
+
		return (-1);
+
	}
+

+
	if (argc == 2)
+
		dest = argv[2];
+

+
	if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK) {
+
		pkg_error_warn("can not open database");
+
		pkgdb_close(db);
+
		return (EPKG_FATAL);
+
	}
+

+
	if (argv[1][1] == 'd') {
+
		printf("Dumping database...");
+
		fflush(stdout);
+
		pkgdb_dump(db, dest);
+
		printf("Done\n");
+
	}
+

+
	if (argv[1][1] == 'r') {
+
		fprintf(stderr, "not yet implemented\n");
+
	}
+
}
added pkg/backup.h
@@ -0,0 +1,6 @@
+
#ifndef _BACKUP_H
+
#define _BACKUP_H
+

+
int exec_backup(int, char **);
+
void usage_backup(void);
+
#endif