Skip to content

Commit

Permalink
Why the fuck this hasn't been in my last commit?
Browse files Browse the repository at this point in the history
  • Loading branch information
bapt committed Aug 7, 2011
1 parent 75fa8c4 commit 90d9d1c
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 11 deletions.
2 changes: 1 addition & 1 deletion libpkg/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ SRCS= pkg.c \
pkg_upgrade.c \
pkg_version.c \
pkgdb.c \
dump.c \
backup.c \
fetch.c \
packing.c \
scripts.c
Expand Down
64 changes: 64 additions & 0 deletions libpkg/backup.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <archive_entry.h>
#include <string.h>

#include "pkg.h"
Expand Down Expand Up @@ -31,9 +32,72 @@ pkgdb_dump(struct pkgdb *db, char *dest)
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);
if (pkg_get(pkg, PKG_MTREE) != NULL) {
sbuf_clear(path);
sbuf_printf(path, "%s-%s.mtree", pkg_get(pkg, PKG_NAME), pkg_get(pkg, PKG_VERSION));
packing_append_buffer(pack, pkg_get(pkg, PKG_MTREE), sbuf_data(path), strlen(pkg_get(pkg, PKG_MTREE)));
}
}

sbuf_delete(path);
packing_finish(pack);
return (EPKG_OK);
}

int
pkgdb_load(struct pkgdb *db, char *dest)
{
struct pkg *pkg = NULL;
struct archive *a;
struct archive_entry *ae;
const char *path;
size_t len;
char *buf;
size_t size;
int retcode = EPKG_OK;

a = archive_read_new();
archive_read_support_compression_all(a);
archive_read_support_format_tar(a);

if (archive_read_open_filename(a, dest, 4096) != ARCHIVE_OK) {
EMIT_PKG_ERROR("archiv_read_open_filename(%s): %s", path, archive_error_string(a));
retcode = EPKG_FATAL;
goto cleanup;
}

while (archive_read_next_header(a, &ae) == ARCHIVE_OK) {
path = archive_entry_pathname(ae);
len = strlen(path);
if (len < 6)
continue;
if (!strcmp(path + len - 5, ".yaml")) {
if (pkg == NULL) {
pkg_new(&pkg, PKG_FILE);
} else {
pkgdb_register_finale(db, pkgdb_register_pkg(db, pkg ));
pkg_reset(pkg, PKG_FILE);
}
size = archive_entry_size(ae);
buf = calloc(1, size + 1);
archive_read_data(a, buf, size);
pkg_parse_manifest(pkg, buf);
free(buf);
} else if (!strcmp(path + len - 6, ".mtree")) {
size = archive_entry_size(ae);
buf = calloc(1, size + 1);
archive_read_data(a, buf, size);
pkg_set(pkg, PKG_MTREE, buf);
free(buf);
} else
continue;
}

cleanup:
if (a != NULL)
archive_read_finish(a);
pkgdb_close(db);
pkg_free(pkg);

return (retcode);
}
1 change: 1 addition & 0 deletions libpkg/pkg.h
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ void pkgdb_close(struct pkgdb *db);
*/

int pkgdb_dump(struct pkgdb *db, char *dest);
int pkgdb_load(struct pkgdb *db, char *dest);

/**
* Whether a package database instance has a particular flag.
Expand Down
3 changes: 1 addition & 2 deletions libpkg/pkg_add.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <libgen.h>
#include <stdlib.h>
#include <string.h>
#include <fnmatch.h>
#include <errno.h>

#include "pkg.h"
Expand Down Expand Up @@ -178,7 +177,7 @@ pkg_add2(struct pkgdb *db, const char *path, int upgrade, int automatic)
ext);

if (access(dpath, F_OK) == 0) {
if (pkg_add(db, dpath) != EPKG_OK) {
if (pkg_add2(db, dpath, 0, 1) != EPKG_OK) {
retcode = EPKG_FATAL;
goto cleanup;
}
Expand Down
1 change: 0 additions & 1 deletion libpkg/pkg_create_repo.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <sys/stat.h>

#include <errno.h>
#include <fnmatch.h>
#include <sqlite3.h>
#include <fts.h>
#include <unistd.h>
Expand Down
1 change: 1 addition & 0 deletions pkg/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ SRCS= add.c \
update.c \
upgrade.c \
search.c \
updating.c \
utils.c \
version.c \
which.c
Expand Down
12 changes: 7 additions & 5 deletions pkg/backup.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,24 @@ exec_backup(int argc, char **argv)
if (argc == 3)
dest = argv[2];

if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK) {
if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK)
return (EX_IOERR);
}

if (argv[1][1] == 'd') {
printf("Dumping database...");
fflush(stdout);
if (pkgdb_dump(db, dest) == EPKG_FATAL)
return (EPKG_FATAL);

printf("Done\n");
printf("done\n");
}

if (argv[1][1] == 'r') {
fprintf(stderr, "not yet implemented\n");
return (EPKG_FATAL);
printf("Restoring database...");
fflush(stdout);
if (pkgdb_load(db, dest) == EPKG_FATAL)
return (EPKG_FATAL);
printf("done\n");
}

pkgdb_close(db);
Expand Down
3 changes: 3 additions & 0 deletions pkg/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ event_callback(void *data __unused, struct pkg_event *ev)
printf("Installing %s-%s...",
pkg_get(ev->e_install_begin.pkg, PKG_NAME),
pkg_get(ev->e_install_begin.pkg, PKG_VERSION));
fflush(stdout);
break;
case PKG_EVENT_INSTALL_FINISHED:
printf(" done\n");
Expand All @@ -40,6 +41,7 @@ event_callback(void *data __unused, struct pkg_event *ev)
printf("Deinstalling %s-%s...",
pkg_get(ev->e_deinstall_begin.pkg, PKG_NAME),
pkg_get(ev->e_deinstall_begin.pkg, PKG_VERSION));
fflush(stdout);
break;
case PKG_EVENT_DEINSTALL_FINISHED:
printf(" done\n");
Expand All @@ -49,6 +51,7 @@ event_callback(void *data __unused, struct pkg_event *ev)
pkg_get(ev->e_upgrade_finished.pkg, PKG_NAME),
pkg_get(ev->e_upgrade_finished.pkg, PKG_VERSION),
pkg_get(ev->e_upgrade_finished.pkg, PKG_NEWVERSION));
fflush(stdout);
break;
case PKG_EVENT_UPGRADE_FINISHED:
printf("done\n");
Expand Down
2 changes: 2 additions & 0 deletions pkg/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "repo.h"
#include "search.h"
#include "update.h"
#include "updating.h"
#include "upgrade.h"
#include "version.h"
#include "which.h"
Expand All @@ -51,6 +52,7 @@ static struct commands {
{ "register", exec_register, usage_register},
{ "repo", exec_repo, usage_repo},
{ "update", exec_update, usage_update},
{ "updating", exec_updating, usage_updating},
{ "upgrade", exec_upgrade, usage_upgrade},
{ "version", exec_version, usage_version},
{ "which", exec_which, usage_which},
Expand Down
4 changes: 2 additions & 2 deletions ports/bsd.pkgng.mk
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ fake-pkg:
[ -f ${PKGPOSTUPGRADE} ] && ${CP} ${PKGPOSTUPGRADE} ${METADIR}/+POST_UPGRADE; \
${CP} ${DESCR} ${METADIR}/+DESC; \
[ -f ${PKGMESSAGE} ] && ${CP} ${PKGMESSAGE} ${METADIR}/+DISPLAY || return 0
.if !defined(NO_MTREE) && defined(MTREE_FILE)
@${CP} ${MTREE_FILE} ${METADIR}/+MTREE_DIRS
.if !defined(NO_MTREE)
@[ -f ${MTREE_FILE} ] && ${CP} ${MTREE_FILE} ${METADIR}/+MTREE_DIRS || return 0
.endif
.if defined(INSTALLS_DEPENDS)
@${PKG_CMD} -d -l -m ${METADIR} -f ${TMPPLIST}
Expand Down

0 comments on commit 90d9d1c

Please sign in to comment.