From: pcanterino <> Date: Wed, 6 Jul 2005 14:36:34 +0000 (+0000) Subject: Implemented experimental feature of copying a whole directory. X-Git-Tag: version_3_0~13 X-Git-Url: https://git.p6c8.net/devedit.git/commitdiff_plain/6cbef69555b48386fee70b73bac2c3df4d15ff6a?ds=sidebyside Implemented experimental feature of copying a whole directory. Currently the target the user wants to copy the directory to must not exist. I hope I will be able to change this in future. --- diff --git a/errors.conf b/errors.conf index b2cbb57..83e924e 100644 --- a/errors.conf +++ b/errors.conf @@ -8,7 +8,8 @@ command_unknown = Unknown command: '{COMMAND}' copy_failed = Could not copy '{FILE}' to '{NEW_FILE}'. create_above_root = You are not allowed to create files and directories above the virtual root directory. delete_failed = Could not delete file '{FILE}'. -dir_copy = This editor is not able to copy directories. +dir_copy_self = You may not copy a directory into itself. +dir_move_self = You may not move a directory into itself. dir_edit = You cannot edit directories. dir_no_create = You have not enough permissions to create a file in directory '{DIR}'. dir_not_exist = The directory where you want to create this file or directory does not exist. diff --git a/modules/Command.pm b/modules/Command.pm index b2bbfe9..d910bda 100644 --- a/modules/Command.pm +++ b/modules/Command.pm @@ -6,7 +6,7 @@ package Command; # Execute Dev-Editor's commands # # Author: Patrick Canterino -# Last modified: 2005-06-14 +# Last modified: 2005-07-06 # use strict; @@ -581,61 +581,90 @@ sub exec_copy($$) my $new_physical = $data->{'new_physical'}; return error($config->{'errors'}->{'link_copy'},$dir) if(-l $physical); - return error($config->{'errors'}->{'dir_copy'},$dir) if(-d $physical); - return error($config->{'errors'}->{'no_copy'},$dir) unless(-r $physical); if($new_physical) { my $new_virtual = multi_string($data->{'new_virtual'}); my $new_dir = upper_path($new_virtual->{'normal'}); - if(-e $new_physical) + if(-d $physical) { - return error($config->{'errors'}->{'link_replace'},$new_dir) if(-l $new_physical); - return error($config->{'errors'}->{'dir_replace'},$new_dir) if(-d $new_physical); - return error($config->{'errors'}->{'exist_no_write'},$new_dir,{FILE => $new_virtual->{'html'}}) unless(-w $new_physical); + return error($config->{'errors'}->{'no_copy'},$dir) unless(-x $physical); + return error($config->{'errors'}->{'file_exists'},$dir,{FILE => $new_virtual->{'html'}}) if(-e $new_physical); + return error($config->{'errors'}->{'dir_copy_self'},$dir) if(index($new_virtual->{'normal'},$virtual) == 0); - if(not $data->{'cgi'}->param('confirmed')) + dir_copy($physical,$new_physical) or return error($config->{'errors'}->{'copy_failed'},$dir,{FILE => encode_html($virtual), NEW_FILE => $new_virtual->{'html'}}); + return devedit_reload({command => 'show', file => $new_dir}); + } + else + { + if(-e $new_physical) { - my $tpl = new Template; - $tpl->read_file($config->{'templates'}->{'confirm_replace'}); - - $tpl->fillin('FILE',encode_html($virtual)); - $tpl->fillin('NEW_FILE',$new_virtual->{'html'}); - $tpl->fillin('NEW_FILENAME',file_name($new_virtual->{'html'})); - $tpl->fillin('NEW_DIR',encode_html($new_dir)); - $tpl->fillin('DIR',encode_html($dir)); - $tpl->fillin('DIR_URL',escape($dir)); - - $tpl->fillin('COMMAND','copy'); - $tpl->fillin('URL',encode_html(equal_url($config->{'httproot'},$virtual))); - $tpl->fillin('SCRIPT',$script); - - my $output = header(-type => 'text/html'); - $output .= $tpl->get_template; - - return \$output; + return error($config->{'errors'}->{'link_replace'},$new_dir) if(-l $new_physical); + return error($config->{'errors'}->{'dir_replace'},$new_dir) if(-d $new_physical); + return error($config->{'errors'}->{'exist_no_write'},$new_dir,{FILE => $new_virtual->{'html'}}) unless(-w $new_physical); + + if(not $data->{'cgi'}->param('confirmed')) + { + my $tpl = new Template; + $tpl->read_file($config->{'templates'}->{'confirm_replace'}); + + $tpl->fillin('FILE',encode_html($virtual)); + $tpl->fillin('NEW_FILE',$new_virtual->{'html'}); + $tpl->fillin('NEW_FILENAME',file_name($new_virtual->{'html'})); + $tpl->fillin('NEW_DIR',encode_html($new_dir)); + $tpl->fillin('DIR',encode_html($dir)); + $tpl->fillin('DIR_URL',escape($dir)); + + $tpl->fillin('COMMAND','copy'); + $tpl->fillin('URL',encode_html(equal_url($config->{'httproot'},$virtual))); + $tpl->fillin('SCRIPT',$script); + + my $output = header(-type => 'text/html'); + $output .= $tpl->get_template; + + return \$output; + } } - } - copy($physical,$new_physical) or return error($config->{'errors'}->{'copy_failed'},$dir,{FILE => encode_html($virtual), NEW_FILE => $new_virtual->{'html'}}); - return devedit_reload({command => 'show', file => $new_dir}); + copy($physical,$new_physical) or return error($config->{'errors'}->{'copy_failed'},$dir,{FILE => encode_html($virtual), NEW_FILE => $new_virtual->{'html'}}); + return devedit_reload({command => 'show', file => $new_dir}); + } } else { - my $tpl = new Template; - $tpl->read_file($config->{'templates'}->{'copyfile'}); + if(-d $physical) + { + my $tpl = new Template; + $tpl->read_file($config->{'templates'}->{'copydir'}); - $tpl->fillin('FILE',encode_html($virtual)); - $tpl->fillin('DIR',encode_html($dir)); - $tpl->fillin('DIR_URL',escape($dir)); - $tpl->fillin('URL',encode_html(equal_url($config->{'httproot'},$virtual))); - $tpl->fillin('SCRIPT',$script); + $tpl->fillin('FILE',encode_html($virtual)); + $tpl->fillin('DIR',encode_html($dir)); + $tpl->fillin('DIR_URL',escape($dir)); + $tpl->fillin('URL',encode_html(equal_url($config->{'httproot'},$virtual))); + $tpl->fillin('SCRIPT',$script); - my $output = header(-type => 'text/html'); - $output .= $tpl->get_template; + my $output = header(-type => 'text/html'); + $output .= $tpl->get_template; - return \$output; + return \$output; + } + else + { + my $tpl = new Template; + $tpl->read_file($config->{'templates'}->{'copyfile'}); + + $tpl->fillin('FILE',encode_html($virtual)); + $tpl->fillin('DIR',encode_html($dir)); + $tpl->fillin('DIR_URL',escape($dir)); + $tpl->fillin('URL',encode_html(equal_url($config->{'httproot'},$virtual))); + $tpl->fillin('SCRIPT',$script); + + my $output = header(-type => 'text/html'); + $output .= $tpl->get_template; + + return \$output; + } } } diff --git a/modules/File/Access.pm b/modules/File/Access.pm index 70a1c04..e0f4e55 100644 --- a/modules/File/Access.pm +++ b/modules/File/Access.pm @@ -7,7 +7,7 @@ package File::Access; # using only one command # # Author: Patrick Canterino -# Last modified: 2005-04-09 +# Last modified: 2005-07-05 # use strict; @@ -18,11 +18,14 @@ use vars qw(@EXPORT use Fcntl qw(:DEFAULT :flock); +use File::Copy; + ### Export ### use base qw(Exporter); -@EXPORT = qw(dir_read +@EXPORT = qw(dir_copy + dir_read file_create file_lock file_read @@ -38,6 +41,49 @@ use base qw(Exporter); $has_flock = eval { local $SIG{'__DIE__'}; flock(STDOUT,0); 1 }; +# dir_copy() +# +# Copy a directory +# +# Params: 1. Directory to copy +# 2. Target +# +# Return: Status code (Boolean) + +sub dir_copy($$) +{ + my ($dir,$target) = @_; + + return unless(-d $dir); + + my $entries = dir_read($dir) or return; + + my $dirs = $entries->{'dirs'}; + my $files = $entries->{'files'}; + + mkdir($target,0777) unless(-d $target); + + foreach my $directory(@$dirs) + { + unless(-d $target.'/'.$directory) + { + mkdir($target.'/'.$directory,0777) or next; + } + + if(-r $target.'/'.$directory && -x $target.'/'.$directory) + { + dir_copy($dir.'/'.$directory,$target.'/'.$directory) or next; + } + } + + foreach my $file(@$files) + { + copy($dir.'/'.$file,$target.'/'.$file) or next; + } + + return 1; +} + # dir_read() # # Collect the files and directories in a directory diff --git a/templates.conf b/templates.conf index 192ce05..055b51b 100644 --- a/templates.conf +++ b/templates.conf @@ -6,6 +6,7 @@ chprop = templates/chprop.htm confirm_replace = templates/confirm_replace.htm confirm_rmdir = templates/confirm_rmdir.htm confirm_rmfile = templates/confirm_rmfile.htm +copydir = templates/copydir.htm copyfile = templates/copyfile.htm dirlist = templates/dirlist.htm dirlist_dir = templates/dirlist_dir.htm diff --git a/templates/copydir.htm b/templates/copydir.htm new file mode 100644 index 0000000..b0d495d --- /dev/null +++ b/templates/copydir.htm @@ -0,0 +1,36 @@ + + + + +Copy directory {FILE} + + + + +

Copy directory {FILE}

+ +

(equals {URL})

+ +

Back to {DIR}

+ +
+ +
+ + + +

Copy directory '{FILE}' to:
+{DIR}

+ +

+
+ +

Note:
+The target you want this directory to copy to must not exist!

+ +
+ +

About Dev-Editor

+ + \ No newline at end of file diff --git a/templates/dirlist_dir.htm b/templates/dirlist_dir.htm index 8c30d44..d3a6f04 100644 --- a/templates/dirlist_dir.htm +++ b/templates/dirlist_dir.htm @@ -2,5 +2,5 @@ [SUBDIR] {DATE}{IF gmt} (GMT){ENDIF} {IF !forbidden}{IF readable}{DIR_NAME}/{ELSE}{DIR_NAME}/{ENDIF}{ELSE}{DIR_NAME}/{ENDIF} -({IF !forbidden}{IF dir_writeable}Rename | Delete | {ENDIF}{IF users}Chmod/Chgrp | {ENDIF}{ENDIF}View in Browser) +({IF !forbidden}{IF readable}Copy | {ENDIF}{IF dir_writeable}Rename | Delete |{ENDIF}{IF users} Chmod/Chgrp | {ENDIF}{ENDIF}View in Browser)