dtas-all
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] dtas-*edit: account for editors which rename over files


From: Eric Wong
Subject: [PATCH] dtas-*edit: account for editors which rename over files
Date: Mon, 23 Sep 2013 05:27:34 +0000

We must not assume the temporary file remains in place while
$EDITOR/$VISUAL is running, as it is common for editors to rename
over a file to atomically replace existing files.
---
 bin/dtas-sinkedit   | 3 +--
 bin/dtas-sourceedit | 6 +++---
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/bin/dtas-sinkedit b/bin/dtas-sinkedit
index 93a4fe9..8a42a7b 100755
--- a/bin/dtas-sinkedit
+++ b/bin/dtas-sinkedit
@@ -18,8 +18,7 @@ orig = YAML.load(buf)
 tmp.write(buf << DTAS_DISCLAIMER)
 cmd = "#{editor} #{tmp.path}"
 system(cmd) or abort "#{cmd} failed: #$?"
-tmp.rewind
-sink = YAML.load(tmp.read)
+sink = YAML.load(File.read(tmp.path))
 
 cmd = %W(sink ed #{name})
 update_cmd_env(cmd, orig, sink)
diff --git a/bin/dtas-sourceedit b/bin/dtas-sourceedit
index 0c8aeb5..87d16ee 100755
--- a/bin/dtas-sourceedit
+++ b/bin/dtas-sourceedit
@@ -22,16 +22,16 @@ abort(buf) if buf =~ /\AERR/
 orig = YAML.load(buf)
 
 if st_in.file? || st_in.pipe?
-  tmp = $stdin
+  buf = $stdin.read
 else
   tmp = tmpyaml
   tmp.write(buf << DTAS_DISCLAIMER)
   cmd = "#{editor} #{tmp.path}"
   system(cmd) or abort "#{cmd} failed: #$?"
-  tmp.rewind
+  buf = File.read(tmp.path)
 end
 
-source = YAML.load(tmp.read)
+source = YAML.load(buf)
 cmd = %W(source ed #{name})
 update_cmd_env(cmd, orig, source)
 
-- 
1.8.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]