Make segment compression/encryption filter to command-line-selectable.
authorMichael Vrable <mvrable@cs.ucsd.edu>
Mon, 11 Jun 2007 21:45:12 +0000 (14:45 -0700)
committerMichael Vrable <mvrable@turin.ucsd.edu>
Mon, 11 Jun 2007 21:45:12 +0000 (14:45 -0700)
scandir.cc
store.cc
store.h

index 52c82f8..3634b59 100644 (file)
@@ -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;
index 57ee11b..cf3eea9 100644 (file)
--- 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 (file)
--- 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