]> git.mjollnir.org Git - cil.git/commitdiff
Support editors that use "atomic write"
authorPedro Melo <melo@simplicidade.org>
Fri, 6 Mar 2009 06:45:29 +0000 (06:45 +0000)
committerAndrew Chilton <andychilton@gmail.com>
Tue, 4 Oct 2011 04:22:13 +0000 (17:22 +1300)
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 <melo@simplicidade.org>
lib/CIL/Utils.pm

index d55350983f547445a61ec61c85bbe3a52a10b5e7..475efe9b42dda989004ace1d6a7918a49c56462b 100644 (file)
@@ -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