Expand directory when entered as additonal file
authorJamie Cameron <jcameron@webmin.com>
Fri, 28 Dec 2007 07:10:53 +0000 (07:10 +0000)
committerJamie Cameron <jcameron@webmin.com>
Fri, 28 Dec 2007 07:10:53 +0000 (07:10 +0000)
backup-config/CHANGELOG
backup-config/backup-config-lib.pl

index 8af6eff..dc23c85 100644 (file)
@@ -10,3 +10,5 @@ Made the backup email contents translatable.
 Added a warning if % is used in filenames but strftime substition is not enabled.
 ---- Changes since 1.330 ----
 Added tabs to reduce the size of the main page.
+---- Changes since 1.390 ----
+When a directory is entered as an additional path to backup, it will be expanded to the list of all files under it when the backup is done.
index 9c9b567..7527fb5 100644 (file)
@@ -237,8 +237,18 @@ if ($_[4]) {
 
 # Add other files
 foreach my $f (@{$_[6]}) {
-       push(@files, $f);
-       push(@{$manifestfiles{"other"}}, $f);
+       if (-d $f) {
+               # A directory .. recursively expand
+               foreach my $sf (&expand_directory($f)) {
+                       push(@files, $sf);
+                       push(@{$manifestfiles{"other"}}, $sf);
+                       }
+               }
+       else {
+               # Just one file
+               push(@files, $f);
+               push(@{$manifestfiles{"other"}}, $f);
+               }
        }
 
 # Save the manifest files
@@ -576,5 +586,25 @@ $webmin || !$nofiles || $others || &error($text{'save_ewebmin'});
 return ($webmin, $nofiles, $others);
 }
 
+sub expand_directory
+{
+local ($dir) = @_;
+local @rv;
+opendir(EXPAND, $dir);
+local @sf = readdir(EXPAND);
+closedir(EXPAND);
+foreach my $sf (@sf) {
+       next if ($sf eq "." || $sf eq "..");
+       local $path = "$dir/$sf";
+       if (-l $path || !-d $path) {
+               push(@rv, $path);
+               }
+       elsif (-d $sf) {
+               push(@rv, &expand_directory($path));
+               }
+       }
+return @rv;
+}
+
 1;