- return exec_unlock($data,$config);
- }
- else
- {
- return error("Saving of file '".encode_entities($virtual)."' failed'. The file could be damaged, please check it's integrity.",upper_path($virtual));
+ my $md5 = new Digest::MD5;
+ $md5->addfile(*FILE);
+
+ my $md5file = $md5->hexdigest;
+ my $md5data = md5_hex($content);
+
+ if($md5file ne $md5sum && $md5data ne $md5file && not $cgi->param('saveas'))
+ {
+ # The file changed meanwhile
+
+ my $tpl = new Template;
+ $tpl->read_file($config->{'templates'}->{'editfile'});
+
+ $tpl->fillin('ERROR',$config->{'errors'}->{'edit_file_changed'});
+
+ $tpl->fillin('FILE',$virtual);
+ $tpl->fillin('DIR',$dir);
+ $tpl->fillin('URL',equal_url($config->{'httproot'},$virtual));
+ $tpl->fillin('SCRIPT',$script);
+ $tpl->fillin('MD5SUM',$md5file);
+ $tpl->fillin('CONTENT',encode_entities($content));
+
+ $tpl->parse_if_block('error',1);
+
+ my $data = header(-type => 'text/html');
+ $data .= $tpl->get_template;
+
+ $output = \$data;
+ }
+ else
+ {
+ if($md5data ne $md5file)
+ {
+ seek(FILE,0,0);
+ truncate(FILE,0);
+
+ print FILE $content;
+ }
+
+ $output = devedit_reload({command => 'show', file => $dir});
+ }
+
+ close(FILE);
+
+ return $output;