--- loncom/interface/portfolio.pm 2004/09/06 23:11:57 1.36 +++ loncom/interface/portfolio.pm 2004/09/06 23:59:05 1.37 @@ -407,20 +407,37 @@ sub upload { sub createdir { my ($r)=@_; - #FIXME 1) file exists in place of dir (errormessage needs improvement) my $newdir=&Apache::lonnet::clean_filename($ENV{'form.newdir'}); if ($newdir eq '') { - $r->print(''. - &mt("Error: no valid directory name was provided."). - '
'); - $r->print(&done()); - return; + $r->print(''. + &mt("Error: no directory name was provided."). + '
'); + $r->print(&done()); + return; } - my $result=&Apache::lonnet::mkdiruserfile($ENV{'user.name'}, - $ENV{'user.domain'},'portfolio'.$ENV{'form.currentpath'}.$newdir); - if ($result ne 'ok') { - $r->print(' An errror occured ('.$result. - ') while trying to create a new directory '.&display_file().'
'); + my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'}, + $ENV{'user.name'}). + '/userfiles/portfolio'; + my @dir_list=&Apache::lonnet::dirlist($ENV{'form.currentpath'}, + $ENV{'user.domain'}, + $ENV{'user.name'},$portfolio_root); + my $found_file = 0; + foreach my $line (@dir_list) { + my ($filename)=split(/\&/,$line,2); + if ($filename eq $newdir){ + $found_file = 1; + } + } + if ($found_file){ + $r->print(' Unable to create a directory named '.$newdir. + ' a file or directory by that name already exists.
'); + } else { + my $result=&Apache::lonnet::mkdiruserfile($ENV{'user.name'}, + $ENV{'user.domain'},'portfolio'.$ENV{'form.currentpath'}.$newdir); + if ($result ne 'ok') { + $r->print(' An errror occured ('.$result. + ') while trying to create a new directory '.&display_file().'
'); + } } $r->print(&done()); }