summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xsamba_wizard/Samba.pm34
1 files changed, 33 insertions, 1 deletions
diff --git a/samba_wizard/Samba.pm b/samba_wizard/Samba.pm
index db8f3fe1..c70c7bef 100755
--- a/samba_wizard/Samba.pm
+++ b/samba_wizard/Samba.pm
@@ -157,9 +157,15 @@ $o->{pages} = {
post => \&check_dir,
data => [
{ label => N("Shared directory:"), val => \$o->{var}{wiz_dir} },
+ { text => N("Create shared directory if it doesn't exists"), type => 'bool', val => \$o->{var}{create_missing_directory} },
],
next => 'ask_access'
},
+ error_in_create_missing_dir => {
+ name => N("Error.") . "\n\n" . N("Failed to create directory."),
+ ignore => 1,
+ next => 'ask_dir'
+ },
error_in_dir => {
name => N("Error.") . "\n\n" . N("The path you entered does not exist."),
ignore => 1,
@@ -261,8 +267,34 @@ sub check_services {
$o->{var}{wiz_do_printer_sharing} and return 'ask_printers';
}
+sub wiz_mkdir_p {
+ my ($dir) = @_;
+ if (-d $dir) {
+ # Do nothing, directory exists
+ } elsif (-e $dir) {
+ # Directory is file, we are not going to delete it
+ return 0;
+ } else {
+ # Create parent directory
+ wiz_mkdir_p(dirname($dir)) or return 0;
+
+ # Create our directory
+ mkdir($dir, 0755) or return 0;
+ }
+ 1;
+}
+
+
sub check_dir {
- -d ($o->{var}{wiz_dir}) or return 'error_in_dir'
+ if (! -d $o->{var}{wiz_dir})
+ {
+ if ($o->{var}{create_missing_directory}) {
+ wiz_mkdir_p($o->{var}{wiz_dir}) or return 'error_in_create_missing_dir';
+ } else {
+ return 'error_in_dir';
+ }
+ }
+ return 0;
}
# the "__" before comment is to avoid conflicts with possible "comment" variable