From: Pedro Melo Date: Fri, 6 Mar 2009 06:45:29 +0000 (+0000) Subject: Support editors that use "atomic write" X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=9cae9596f173dff8ff9534cce095374fe47f5196;p=cil.git Support editors that use "atomic write" Some editors (like TextMate and at least my configuration of Vim) save the file using an "atomic write". They write the file to a new, temporary filename, and then rename the new filename to the old filename. This assures that the file is never "half-written" or corrupted in case of a crash. The solicit() code didn't support this. By using seek() to rewind the file pointer he was assuming that the editor was reusing the same inode. Signed-off-by: Pedro Melo --- diff --git a/lib/CIL/Utils.pm b/lib/CIL/Utils.pm index d553509..475efe9 100644 --- a/lib/CIL/Utils.pm +++ b/lib/CIL/Utils.pm @@ -166,11 +166,12 @@ sub solicit { : "could not launch ($editor) program: $!"; } - unless ( seek $fh, 0, 0 ) { + my $new_fh; + if (!open($new_fh, '<', $filename)) { croak "could not seek on temp file: errno=$!"; } - return $fh; + return $new_fh; } # this method based on Recipe 15.2