summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2003-08-26 23:50:11 +0000
committerLennart Poettering <lennart@poettering.net>2003-08-26 23:50:11 +0000
commit3f1b7c57a01244dbc6b5ba8ebd029aff45edfb3c (patch)
tree78afb3a938028ff50e286f9699348c47ca3a0745
parentf5c2550af23d2b6f82d0b2540af7c1afff9c61aa (diff)
extract added
git-svn-id: file:///home/lennart/svn/public/syrep/trunk@5 07ea20a6-d2c5-0310-9e02-9ef735347d72
-rw-r--r--src/Makefile2
-rw-r--r--src/dump.c2
-rw-r--r--src/md5util.c14
-rw-r--r--src/package.c2
-rw-r--r--src/package.h2
-rw-r--r--src/syrep.c37
-rw-r--r--src/syrep.ggo3
7 files changed, 50 insertions, 12 deletions
diff --git a/src/Makefile b/src/Makefile
index 45f00b2..addd2e8 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -4,7 +4,7 @@ CC=gcc
all: syrep
-syrep: cache.o update.o util.o syrep.o md5.o md5util.o context.o package.o dbutil.o cmdline.o info.o history.o dump.o list.o diff.o merge.o
+syrep: cache.o update.o util.o syrep.o md5.o md5util.o context.o package.o dbutil.o cmdline.o info.o history.o dump.o list.o diff.o merge.o extract.o
$(CC) -g $^ -o $@ -ldb
cmdline.c cmdline.h: syrep.ggo Makefile
diff --git a/src/dump.c b/src/dump.c
index c09da8d..06d8e28 100644
--- a/src/dump.c
+++ b/src/dump.c
@@ -7,7 +7,7 @@
#include "dump.h"
#include "package.h"
-static int foreach(struct package *p, char *name, char *path, void *u) {
+static int foreach(struct package *p, const char *name, const char *path, void *u) {
struct stat st;
uint32_t size;
diff --git a/src/md5util.c b/src/md5util.c
index 41a5a31..a49e5d5 100644
--- a/src/md5util.c
+++ b/src/md5util.c
@@ -21,6 +21,8 @@
#include <sys/mman.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
#include "md5util.h"
#include "md5.h"
@@ -49,7 +51,7 @@ int fdmd5(int fd, size_t l, char *md) {
m = l < MMAPSIZE ? l : MMAPSIZE;
- while (l > 0 && (d = mmap(NULL, m, PROT_READ, MAP_SHARED, fd, o))) {
+ while (l > 0 && ((d = mmap(NULL, m, PROT_READ, MAP_SHARED, fd, o)) != MAP_FAILED)) {
md5_append(&s, d, m);
munmap(d, m);
@@ -61,7 +63,7 @@ int fdmd5(int fd, size_t l, char *md) {
if (l > 0) {
void *p;
- fprintf(stderr, "mmap() failed\n");
+ fprintf(stderr, "mmap() failed: %s\n", strerror(errno));
if (!(p = malloc(BUFSIZE)))
r = -1;
@@ -70,7 +72,13 @@ int fdmd5(int fd, size_t l, char *md) {
for (;;) {
ssize_t r;
- if ((r = read(fd, p, BUFSIZE)) <= 0)
+ if ((r = read(fd, p, BUFSIZE)) < 0) {
+ fprintf(stderr, "read(): %s\n", strerror(errno));
+ free(p);
+ return -1;
+ }
+
+ if (!r)
break;
md5_append(&s, p, r);
diff --git a/src/package.c b/src/package.c
index 168a6d8..5a741eb 100644
--- a/src/package.c
+++ b/src/package.c
@@ -298,7 +298,7 @@ void package_remove(struct package *p) {
}
-int package_foreach(struct package *p, int (*cb) (struct package *p, char *name, char *path, void *u), void *u) {
+int package_foreach(struct package *p, int (*cb) (struct package *p, const char *name, const char *path, void *u), void *u) {
struct package_item *i;
assert(p);
diff --git a/src/package.h b/src/package.h
index 62aca3b..56a3d34 100644
--- a/src/package.h
+++ b/src/package.h
@@ -9,6 +9,6 @@ struct package* package_open(const char *fn);
void package_remove(struct package *p);
int package_save(struct package *p, const char *fn);
const char *package_get_item(struct package* p, const char *name);
-int package_foreach(struct package *p, int (*cb) (struct package *p, char *name, char *path, void *u), void *u);
+int package_foreach(struct package *p, int (*cb) (struct package *p, const char *name, const char *path, void *u), void *u);
#endif
diff --git a/src/syrep.c b/src/syrep.c
index 07bbe37..aaf98f4 100644
--- a/src/syrep.c
+++ b/src/syrep.c
@@ -26,6 +26,7 @@
#include "info.h"
#include "history.h"
#include "dump.h"
+#include "extract.h"
struct gengetopt_args_info args;
@@ -137,7 +138,7 @@ finish:
return r;
}
-int do_foreach(int (*func) (struct syrep_db_context *c)) {
+int do_foreach(int (*func) (struct syrep_db_context *c), int m) {
char *path = NULL;
int r = 1, i;
struct syrep_db_context *c = NULL;
@@ -146,6 +147,7 @@ int do_foreach(int (*func) (struct syrep_db_context *c)) {
fprintf(stderr, "WARNING: No repository or snapshot to specified!\n");
for (i = 0; i < args.inputs_num; i++) {
+ static char saved_cwd[PATH_MAX];
if (!(path = strdup(get_attached_filename(args.inputs[i], SYREP_SNAPSHOTFILENAME))))
goto finish;
@@ -155,10 +157,33 @@ int do_foreach(int (*func) (struct syrep_db_context *c)) {
if (args.inputs_num > 1)
fprintf(stderr, "*** %s ***\n", path);
+
+ if (m && args.output_directory_given) {
+ if (getcwd(saved_cwd, sizeof(saved_cwd)) < 0) {
+ fprintf(stderr, "getcwd(): %s\n", strerror(errno));
+ return -1;
+ }
+
+ mkdir(args.output_directory_arg, 0777);
+
+ if (chdir(args.output_directory_arg) < 0) {
+ fprintf(stderr, "Failed to chdir() to directory %s: %s\n", args.output_directory_arg, strerror(errno));
+ return -1;
+ }
+ }
+
if (func(c) < 0)
goto finish;
+ if (m && args.output_directory_given) {
+ if (chdir(saved_cwd) < 0) {
+ fprintf(stderr, "Failed to chdir() back to directory %s: %s\n", saved_cwd, strerror(errno));
+ return -1;
+ }
+ }
+
+
if (args.inputs_num > 1 && i < args.inputs_num-1)
fprintf(stderr, "\n");
@@ -281,11 +306,11 @@ int main(int argc, char *argv[]) {
cmdline_parser(argc, argv, &args);
if (args.list_flag)
- return do_foreach(list);
+ return do_foreach(list, 0);
else if (args.info_flag)
- return do_foreach(info);
+ return do_foreach(info, 0);
else if (args.history_flag)
- return do_foreach(history);
+ return do_foreach(history, 0);
else if (args.diff_flag)
return do_diff();
else if (args.update_flag)
@@ -293,7 +318,9 @@ int main(int argc, char *argv[]) {
else if (args.merge_flag)
return do_merge();
else if (args.dump_flag)
- return do_foreach(dump);
+ return do_foreach(dump, 0);
+ else if (args.extract_flag)
+ return do_foreach(extract, 1);
cmdline_parser_print_help();
diff --git a/src/syrep.ggo b/src/syrep.ggo
index 20aa0bf..216a43d 100644
--- a/src/syrep.ggo
+++ b/src/syrep.ggo
@@ -25,3 +25,6 @@ option "diff" - "Show difference between two repositories or snapshots" flag off
option "merge" - "Merge a snapshot or a repository into a repository" flag off
option "question" - "merge: Ask a question before each action" flag off
+
+option "extract" - "Extract the context of a snapshot or patch" flag off
+ option "output-directory" - "extract: Write output to specified directory" string no