Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
* [sup-devel] [PATCH 1/2] ensure sources.yaml gets flushed to disk
@ 2011-01-18 18:28 Sascha Silbe
  2011-01-18 18:28 ` [sup-devel] [PATCH 2/2] {config, sources}.yaml: preserve symlinks and permissions Sascha Silbe
  0 siblings, 1 reply; 10+ messages in thread
From: Sascha Silbe @ 2011-01-18 18:28 UTC (permalink / raw)
  To: sup-devel

Before renaming sources.yaml we need to fsync() it, otherwise we could end up
with an empty file in case of a crash [1].

[1] http://thunk.org/tytso/blog/2009/03/12/delayed-allocation-and-the-zero-length-file-problem/

Signed-off-by: Sascha Silbe <sascha-pgp@silbe.org>
---
 lib/sup.rb |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/lib/sup.rb b/lib/sup.rb
index edd23c8..09744b4 100644
--- a/lib/sup.rb
+++ b/lib/sup.rb
@@ -98,10 +98,16 @@ module Redwood
     if safe
       safe_fn = "#{File.dirname fn}/safe_#{File.basename fn}"
       mode = File.stat(fn).mode if File.exists? fn
-      File.open(safe_fn, "w", mode) { |f| f.puts o.to_yaml }
+      File.open(safe_fn, "w", mode) do |f|
+        f.puts o.to_yaml
+        f.fsync
+      end
       FileUtils.mv safe_fn, fn
     else
-      File.open(fn, "w") { |f| f.puts o.to_yaml }
+      File.open(fn, "w") do |f|
+        f.puts o.to_yaml
+        f.fsync
+      end
     end
   end
 
-- 
1.7.2.3

_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2011-01-19 18:53 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-18 18:28 [sup-devel] [PATCH 1/2] ensure sources.yaml gets flushed to disk Sascha Silbe
2011-01-18 18:28 ` [sup-devel] [PATCH 2/2] {config, sources}.yaml: preserve symlinks and permissions Sascha Silbe
2011-01-19  3:41   ` Rich Lane
2011-01-19 10:05     ` Sascha Silbe
2011-01-19 15:38   ` William Morgan
2011-01-19 16:42     ` Sascha Silbe
2011-01-19 17:17       ` William Morgan
2011-01-19 18:44         ` Rich Lane
2011-01-19 17:19     ` William Morgan
2011-01-19 18:41       ` Ben Walton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox