From 3addc0c5e928bc7b0fc6ff1ef8b7dff7263cf3ea Mon Sep 17 00:00:00 2001 From: Michael Vrable Date: Mon, 11 Jun 2007 14:45:12 -0700 Subject: [PATCH] Make segment compression/encryption filter to command-line-selectable. --- scandir.cc | 12 ++++++++++-- store.cc | 9 ++++++--- store.h | 7 +++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/scandir.cc b/scandir.cc index 52c82f8..3634b59 100644 --- a/scandir.cc +++ b/scandir.cc @@ -403,8 +403,10 @@ int main(int argc, char *argv[]) while (1) { static struct option long_options[] = { - {"localdb", 1, 0, 0}, // 0 - {"exclude", 1, 0, 0}, // 1 + {"localdb", 1, 0, 0}, // 0 + {"exclude", 1, 0, 0}, // 1 + {"filter", 1, 0, 0}, // 2 + {"filter-extension", 1, 0, 0}, // 3 {NULL, 0, 0, 0}, }; @@ -422,6 +424,12 @@ int main(int argc, char *argv[]) case 1: // --exclude excludes.push_back(optarg); break; + case 2: // --filter + filter_program = optarg; + break; + case 3: // --filter-extension + filter_extension = optarg; + break; default: fprintf(stderr, "Unhandled long option!\n"); return 1; diff --git a/store.cc b/store.cc index 57ee11b..cf3eea9 100644 --- a/store.cc +++ b/store.cc @@ -30,7 +30,9 @@ using std::list; using std::set; using std::string; -static char *const filter_program[] = {"bzip2", "-c", NULL}; +/* Default filter program is bzip2 */ +const char *filter_program = "bzip2 -c"; +const char *filter_extension = ".bz2"; static void cloexec(int fd) { @@ -112,7 +114,7 @@ int Tarfile::spawn_filter(int fd_out) close(fd_out); /* Exec the filter program. */ - execvp(filter_program[0], filter_program); + execlp("/bin/sh", "/bin/sh", "-c", filter_program, NULL); /* Should not reach here except for error cases. */ fprintf(stderr, "Could not exec filter: %m\n"); @@ -204,7 +206,8 @@ ObjectReference TarSegmentStore::write_object(const char *data, size_t len, segment->name = generate_uuid(); - string filename = path + "/" + segment->name + ".tar.bz2"; + string filename = path + "/" + segment->name + ".tar"; + filename += filter_extension; segment->file = new Tarfile(filename, segment->name); segment->count = 0; diff --git a/store.h b/store.h index aa96160..72fde52 100644 --- a/store.h +++ b/store.h @@ -144,4 +144,11 @@ private: ObjectReference ref; }; +/* Program through which segment data is piped before being written to file. */ +extern const char *filter_program; + +/* Extension which should be appended to segments written out (.tar is already + * included; this adds to it) */ +extern const char *filter_extension; + #endif // _LBS_STORE_H -- 2.20.1