Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
From: Sascha Silbe <sascha-pgp@silbe.org>
To: sup-devel <sup-devel@rubyforge.org>
Subject: [sup-devel] [PATCH 1/2] ensure sources.yaml gets flushed to disk
Date: Tue, 18 Jan 2011 19:28:43 +0100	[thread overview]
Message-ID: <1295375324-2496-1-git-send-email-sascha-pgp@silbe.org> (raw)

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


             reply	other threads:[~2011-01-18 19:28 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-18 18:28 Sascha Silbe [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1295375324-2496-1-git-send-email-sascha-pgp@silbe.org \
    --to=sascha-pgp@silbe.org \
    --cc=sascha-ml-reply-to-2011-1@silbe.org \
    --cc=sup-devel@rubyforge.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox