X-Git-Url: https://git.p6c8.net/devedit.git/blobdiff_plain/8bc393b21655cb67a6c0bb7ef450b94c366e7aff..4c99fa1ba416929e3f277e6efb14f93332884ad4:/modules/Command.pm diff --git a/modules/Command.pm b/modules/Command.pm index edd0162..5282396 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-04-09 +# Last modified: 2005-04-15 # use strict; @@ -181,7 +181,7 @@ sub exec_show($$) $ftpl->parse_if_block('link',-l $phys_path); $ftpl->parse_if_block('no_link',not -l $phys_path); $ftpl->parse_if_block('not_readable',not -r $phys_path); - $ftpl->parse_if_block('binary_file',-B $phys_path); + $ftpl->parse_if_block('binary',-B $phys_path); $ftpl->parse_if_block('readonly',not -w $phys_path); $ftpl->parse_if_block('viewable',(-r $phys_path && -T $phys_path && not $too_large) || -l $phys_path); @@ -294,7 +294,7 @@ sub exec_beginedit($$) # ... and show the editing form - my $content = file_read($physical,1); + my $content = file_read($physical); my $md5sum = md5_hex($$content); $$content =~ s/\015\012|\012|\015/\n/g; @@ -336,7 +336,7 @@ sub exec_endedit($$) my $md5sum = $cgi->param('md5sum'); my $output; - if($content && $md5sum) + if(defined $content && $md5sum) { # Normalize newlines @@ -361,15 +361,15 @@ sub exec_endedit($$) local *FILE; sysopen(FILE,$physical,O_RDWR | O_CREAT) or return error($config->{'errors'}->{'edit_failed'},$dir,{FILE => $virtual}); - file_lock(FILE,LOCK_EX) or do { close(FILE); return error($config->{'errors'}->{'edit_failed'},$dir,{FILE => $virtual}) }; - binmode(FILE); + file_lock(*FILE,LOCK_EX) or do { close(FILE); return error($config->{'errors'}->{'edit_failed'},$dir,{FILE => $virtual}) }; my $md5 = new Digest::MD5; $md5->addfile(*FILE); - my $md5_new = $md5->hexdigest; + my $md5file = $md5->hexdigest; + my $md5data = md5_hex($content); - if($md5_new ne $md5sum && not $cgi->param('saveas')) + if($md5file ne $md5sum && $md5data ne $md5file && not $cgi->param('saveas')) { # The file changed meanwhile @@ -382,7 +382,7 @@ sub exec_endedit($$) $tpl->fillin('DIR',$dir); $tpl->fillin('URL',equal_url($config->{'httproot'},$virtual)); $tpl->fillin('SCRIPT',$script); - $tpl->fillin('MD5SUM',$md5_new); + $tpl->fillin('MD5SUM',$md5file); $tpl->fillin('CONTENT',encode_entities($content)); $tpl->parse_if_block('error',1); @@ -396,10 +396,13 @@ sub exec_endedit($$) { # The file was saved successfully! - seek(FILE,0,0); - truncate(FILE,0); + if($md5data ne $md5file) + { + seek(FILE,0,0); + truncate(FILE,0); - print FILE $content; + print FILE $content; + } $output = devedit_reload({command => 'show', file => $dir}); @@ -527,8 +530,8 @@ sub exec_upload($$) return error($config->{'errors'}->{'file_exists'},$virtual,{FILE => $file_virt}) unless($cgi->param('overwrite')); } - my $ascii = $cgi->param('ascii'); - my $handle = $cgi->upload('uploaded_file'); + my $ascii = $cgi->param('ascii'); + my $handle = $cgi->upload('uploaded_file'); return error($config->{'errors'}->{'invalid_upload'},$virtual) unless($handle); @@ -648,8 +651,8 @@ sub exec_rename($$) my $dir = upper_path($virtual); my $new_physical = $data->{'new_physical'}; - return error($config->{'errors'}->{'rename_root'},'/') if($virtual eq '/'); - return error($config->{'errors'}->{'no_rename'},$dir) unless(-w upper_path($physical)); + return error($config->{'errors'}->{'rename_root'},'/') if($virtual eq '/'); + return error($config->{'errors'}->{'no_rename'},$dir) unless(-w upper_path($physical)); if($new_physical) {