From 1acd2892cb4fb5c15801fd49a1cf0640b05b7b97 Mon Sep 17 00:00:00 2001 From: Antoine Ginies Date: Fri, 30 Jul 2004 02:56:58 +0000 Subject: add option to create directory (thx Robert Vojta) --- samba_wizard/Samba.pm | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) 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 -- cgit v1.2.1