$NetBSD$

--- src/rebuild.c.orig	2010-08-23 22:34:16.000000000 +0000
+++ src/rebuild.c
@@ -415,16 +415,13 @@ void scrub_cmd(void){
 **
 */
 void reconstruct_cmd(void) {
+  int i;
   char *zPassword;
   DIR *d;
   struct dirent *pEntry;
   Blob aContent; /* content of the just read artifact */
-  if( g.argc!=4 ){
-    usage("FILENAME DIRECTORY");
-  }
-  if( file_isdir(g.argv[3])!=1 ){
-    printf("\"%s\" is not a directory\n\n", g.argv[3]);
-    usage("FILENAME DIRECTORY");
+  if( g.argc < 4 ){
+    usage("FILENAME DIRECTORY...");
   }
   db_create_repository(g.argv[2]);
   db_open_repository(g.argv[2]);
@@ -432,26 +429,35 @@ void reconstruct_cmd(void) {
   db_begin_transaction();
   db_initial_setup(0, 0, 1);
 
-  d = opendir(g.argv[3]);
-  if( d ){
-    while( (pEntry=readdir(d))!=0 ){
-      Blob path;
-      blob_init(&path, 0, 0);
-      if( pEntry->d_name[0]=='.' ){
-        continue;
-      }
-      if( file_isdir(pEntry->d_name)==1 ){
-        continue;
-      }
-      blob_appendf(&path, "%s/%s", g.argv[3], pEntry->d_name);
-      if( blob_read_from_file(&aContent, blob_str(&path))==-1 ){
-        fossil_panic("Some unknown error occurred while reading \"%s\"", blob_str(&path));
+  for( i = 3; i < g.argc; ++i ) {
+    if( file_isdir(g.argv[i])!=1 ){
+      printf("\"%s\" is not a directory\n\n", g.argv[i]);
+      usage("FILENAME DIRECTORY...");
+    }
+    d = opendir(g.argv[i]);
+    if( d ){
+      while( (pEntry=readdir(d))!=0 ){
+        Blob path;
+        blob_init(&path, 0, 0);
+        if( pEntry->d_name[0]=='.' ){
+          continue;
+        }
+        if( file_isdir(pEntry->d_name)==1 ){
+          continue;
+        }
+        blob_appendf(&path, "%s/%s", g.argv[i], pEntry->d_name);
+        if( blob_read_from_file(&aContent, blob_str(&path))==-1 ){
+          fossil_panic("Some unknown error occurred while reading \"%s\"", blob_str(&path));
+        }
+        content_put(&aContent, 0, 0);
+        blob_reset(&path);
+        blob_reset(&aContent);
       }
-      content_put(&aContent, 0, 0);
     }
-  }
-  else {
-    fossil_panic("Encountered error %d while trying to open \"%s\".", errno, g.argv[3]);
+    else {
+      fossil_panic("Encountered error %d while trying to open \"%s\".", errno, g.argv[i]);
+    }
+    closedir(d);
   }
 
   rebuild_db(0, 1);
