Index: trunk/DataStoreServer/scripts/dsreg
===================================================================
--- trunk/DataStoreServer/scripts/dsreg	(revision 20293)
+++ trunk/DataStoreServer/scripts/dsreg	(revision 23902)
@@ -31,4 +31,5 @@
 my $fileset;
 my $filelist;
+my $empty;
 
 my $fstype;
@@ -64,4 +65,5 @@
         'product=s'     =>      \$product,
         'list=s'        =>      \$filelist,
+        'empty'         =>      \$empty,
         'type=s'        =>      \$fstype,
         'datapath=s'    =>      \$datapath,
@@ -95,5 +97,5 @@
     $fileset = $add;
     $err .= "--type is required\n" unless defined $fstype;
-    $err .= "--list is required\n" unless defined $filelist;
+    $err .= "--list is required\n" unless defined $filelist or $empty;
     if ($linkfiles and $copyfiles) {
         $err .= "only one of --link and --copy is allowed\n";
@@ -251,107 +253,110 @@
     }
 
+
     # Note: There is a race condition here. Somebody could sneak in now and add a fileset with
     # fileset_name = $fileset. So later we'll check again that only one fileset with the name exists
 
-
-    my $in;
-    if ($filelist eq "-") {
-        $in = *STDIN;
-    } else {
-        open $in, "<$filelist" or die  "cannot open filelist file $filelist\n";
-    }
-
-    my $lineno = 0;
+    ## create the fileset directory
+    if (! -e $fileset_dir) {
+        if (!mkdir $fileset_dir) {
+            die("failed trying to create fileset directory $fileset_dir");
+        }
+    }
+
     my @files;
-    while (<$in>) {
-        chomp;
-        $lineno++;
-
-        my $filename;
-        my $bytes;
-        my $md5sum;
-        my $filetype;
-
-        my @fields = split /\|/;
-        if (@fields < 4) {
-            die "malformed input line at $filelist line $lineno: $_\n";
-        }
-        $filename = shift @fields;
-        $bytes    = shift @fields;  # if this is null it will be calculated below
-        $md5sum   = shift @fields;  # if this is null it will be calculated below
-        $filetype = shift @fields;
-
-        # make sure the length of the type specific columns is 8
-        while (@fields < 8) {
-            push @fields, undef;
-        }
-        my $ts_cols = [@fields];
-
-        my $hashref = {
-            'file'      => $filename,
-            'bytes'     => $bytes,
-            'md5sum'    => $md5sum,
-            'type'      => $filetype,
-            'ts_cols'   => $ts_cols,
-        };
-
-        push @files, $hashref;
-    }
-
-    die("empty filelist\n") if (@files == 0);
-
-    # Prepare the fileset directory
-    if ($linkfiles or $copyfiles) {
-        ## create the fileset directory
-        if (! -e $fileset_dir) {
-            if (!mkdir $fileset_dir) {
-                die("failed trying to create fileset directory $fileset_dir");
-            }
-        }
-        eval {
-            ## then copy or symlink the files into place
-            foreach my $ref (@files) {
-                my $src = (defined $abspath ? '' : "$datapath/") . "$ref->{file}";
-		my $filename = fileparse($ref->{file}, ());
-                my $dest = "$fileset_dir/$filename";
-
-                if ($linkfiles) {
-                    if (! symlink $src, $dest) {
-                        die("failed trying to link $src to $dest");
-                    }
-                } else {
-                    if (!copy($src, $dest)) {
-                        die("copy($src, $dest) failed");
+    if (!$empty) {
+        my $in;
+        if ($filelist eq "-") {
+            $in = *STDIN;
+        } else {
+            open $in, "<$filelist" or die  "cannot open filelist file $filelist\n";
+        }
+
+        my $lineno = 0;
+        while (<$in>) {
+            chomp;
+            $lineno++;
+
+            my $filename;
+            my $bytes;
+            my $md5sum;
+            my $filetype;
+
+            my @fields = split /\|/;
+            if (@fields < 4) {
+                die "malformed input line at $filelist line $lineno: $_\n";
+            }
+            $filename = shift @fields;
+            $bytes    = shift @fields;  # if this is null it will be calculated below
+            $md5sum   = shift @fields;  # if this is null it will be calculated below
+            $filetype = shift @fields;
+
+            # make sure the length of the type specific columns is 8
+            while (@fields < 8) {
+                push @fields, undef;
+            }
+            my $ts_cols = [@fields];
+
+            my $hashref = {
+                'file'      => $filename,
+                'bytes'     => $bytes,
+                'md5sum'    => $md5sum,
+                'type'      => $filetype,
+                'ts_cols'   => $ts_cols,
+            };
+
+            push @files, $hashref;
+        }
+
+        die("empty filelist\n") if (@files == 0);
+
+        # Prepare the fileset directory
+        if ($linkfiles or $copyfiles) {
+            eval {
+                ## then copy or symlink the files into place
+                foreach my $ref (@files) {
+                    my $src = (defined $abspath ? '' : "$datapath/") . "$ref->{file}";
+                    my $filename = fileparse($ref->{file}, ());
+                    my $dest = "$fileset_dir/$filename";
+
+                    if ($linkfiles) {
+                        if (! symlink $src, $dest) {
+                            die("failed trying to link $src to $dest");
+                        }
+                    } else {
+                        if (!copy($src, $dest)) {
+                            die("copy($src, $dest) failed");
+                        }
                     }
                 }
-            }
-        };
-        if ($@) { # an error occured
-            print STDERR "error preparing the fileset directory: $@\n";
-
-            if (!$no_cleanup && system "rm -r $fileset_dir") {
-                die("failed to remove $fileset_dir");
-            }
-            exit $PS_EXIT_UNKNOWN_ERROR;
-        }
-    }
-
-    # now calculate the md5sum and file size if they weren't provided
-    foreach my $file (@files) {
-	my $filename = fileparse($file->{file}, ());
-        my $path = "$fileset_dir/$filename";
-        if (! -e $path ) {
-            die "file $path not found";
-        }
-        if (!$file->{bytes}) {
-            my @finfo = stat($path);
-            unless (@finfo) {
-                die ("can't stat $path");
-            }
-            $file->{bytes}  = $finfo[7];
-        }
-        if (!$file->{md5sum}) {
-            # Get MD5 sum
-            $file->{md5sum} = file_md5_hex($path);
+            };
+            if ($@) { # an error occured
+                print STDERR "error preparing the fileset directory: $@\n";
+
+                if (!$no_cleanup && system "rm -r $fileset_dir") {
+                    die("failed to remove $fileset_dir");
+                }
+                exit $PS_EXIT_UNKNOWN_ERROR;
+            }
+        }
+
+        # now calculate the md5sum and file size if they weren't provided
+        foreach my $file (@files) {
+            my $filename = fileparse($file->{file}, ());
+            my $path = "$fileset_dir/$filename";
+            if (! -e $path ) {
+                die "file $path not found";
+            }
+            if (!$file->{bytes}) {
+                my @finfo = stat($path);
+                unless (@finfo) {
+                    die ("can't stat $path");
+                }
+                $file->{bytes}  = $finfo[7];
+            }
+            if (!$file->{md5sum}) {
+                # Get MD5 sum
+                $file->{md5sum} = file_md5_hex($path);
+            }
         }
     }
