From 34d802a181e156ca6420eae59c9ad7918a9c0481 Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Fri, 28 Dec 2007 07:10:53 +0000 Subject: [PATCH] Expand directory when entered as additonal file --- backup-config/CHANGELOG | 2 ++ backup-config/backup-config-lib.pl | 34 ++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/backup-config/CHANGELOG b/backup-config/CHANGELOG index 8af6eff4d..dc23c857d 100644 --- a/backup-config/CHANGELOG +++ b/backup-config/CHANGELOG @@ -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. diff --git a/backup-config/backup-config-lib.pl b/backup-config/backup-config-lib.pl index 9c9b567eb..7527fb529 100644 --- a/backup-config/backup-config-lib.pl +++ b/backup-config/backup-config-lib.pl @@ -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;