From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by 10.42.229.71 with SMTP id jh7cs146975icb; Tue, 18 Jan 2011 11:18:14 -0800 (PST) Received: by 10.231.15.132 with SMTP id k4mr6572930iba.60.1295378293894; Tue, 18 Jan 2011 11:18:13 -0800 (PST) Return-Path: Received: from rubyforge.org (rubyforge.org [205.234.109.19]) by mx.google.com with ESMTP id q5si12346939qcs.31.2011.01.18.11.18.13; Tue, 18 Jan 2011 11:18:13 -0800 (PST) Received-SPF: pass (google.com: domain of sup-devel-bounces@rubyforge.org designates 205.234.109.19 as permitted sender) client-ip=205.234.109.19; Authentication-Results: mx.google.com; spf=pass (google.com: domain of sup-devel-bounces@rubyforge.org designates 205.234.109.19 as permitted sender) smtp.mail=sup-devel-bounces@rubyforge.org Received: from rubyforge.org (rubyforge.org [127.0.0.1]) by rubyforge.org (Postfix) with ESMTP id 11CC2185835E; Tue, 18 Jan 2011 14:18:13 -0500 (EST) Received: from smtp.chost.de (setoy.chost.de [217.160.209.225]) by rubyforge.org (Postfix) with ESMTP id 5DC0A185831A for ; Tue, 18 Jan 2011 13:29:15 -0500 (EST) Received: (qmail 30126 invoked by uid 5015); 18 Jan 2011 18:29:09 -0000 Received: (nullmailer pid 31515 invoked by uid 8193); Tue, 18 Jan 2011 18:29:00 -0000 Received: (nullmailer pid 2582 invoked by uid 8193); Tue, 18 Jan 2011 18:28:56 -0000 From: Sascha Silbe To: sup-devel Date: Tue, 18 Jan 2011 19:28:44 +0100 Message-Id: <1295375324-2496-2-git-send-email-sascha-pgp@silbe.org> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1295375324-2496-1-git-send-email-sascha-pgp@silbe.org> References: <1295375324-2496-1-git-send-email-sascha-pgp@silbe.org> Mail-Followup-To: Subject: [sup-devel] [PATCH 2/2] {config, sources}.yaml: preserve symlinks and permissions X-BeenThere: sup-devel@rubyforge.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: Sascha Silbe , Sup developer discussion List-Id: Sup developer discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: sup-devel-bounces@rubyforge.org Errors-To: sup-devel-bounces@rubyforge.org If config.yaml resp. sources.yaml already exists, preserve the permissions. Also alter the save algorithm to overwrite the file in-place, thus leaving symlinks intact. Signed-off-by: Sascha Silbe --- All invocations of save_yaml_obj now use the "backup" mode, so maybe we should just hardcode it in save_yaml_obj, getting rid of the (existing) safe and (new) backup parameters. bin/sup-config | 2 +- lib/sup.rb | 27 ++++++++++++++++++++++----- lib/sup/source.rb | 8 +------- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/bin/sup-config b/bin/sup-config index 132fd77..c4a64a3 100755 --- a/bin/sup-config +++ b/bin/sup-config @@ -191,7 +191,7 @@ else end end -Redwood::save_yaml_obj $config, Redwood::CONFIG_FN +Redwood::save_yaml_obj $config, Redwood::CONFIG_FN, false, true say "Ok, I've saved you up a nice lil' #{Redwood::CONFIG_FN}." diff --git a/lib/sup.rb b/lib/sup.rb index 09744b4..21bddb2 100644 --- a/lib/sup.rb +++ b/lib/sup.rb @@ -86,7 +86,7 @@ module Redwood module_function :reporting_thread, :record_exception, :exceptions ## one-stop shop for yamliciousness - def save_yaml_obj o, fn, safe=false + def save_yaml_obj o, fn, safe=false, backup=false o = if o.is_a?(Array) o.map { |x| (x.respond_to?(:before_marshal) && x.before_marshal) || x } elsif o.respond_to? :before_marshal @@ -95,16 +95,33 @@ module Redwood o end - if safe + mode = if File.exists? fn + File.stat(fn).mode + else + 0600 + end + + if backup + backup_fn = fn + '.bak' + unless File.exists?(backup_fn) && File.size(fn) == 0 + File.open(backup_fn, "w", mode) do |f| + File.open(fn, "r") { |old_f| FileUtils.copy_stream old_f, f } + f.fsync + end + end + File.open(fn, "w") do |f| + f.puts o.to_yaml + f.fsync + end + elsif 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) do |f| f.puts o.to_yaml f.fsync end FileUtils.mv safe_fn, fn else - File.open(fn, "w") do |f| + File.open(fn, "w", mode) do |f| f.puts o.to_yaml f.fsync end @@ -292,7 +309,7 @@ EOS :col_jump => 2 } begin - Redwood::save_yaml_obj config, filename + Redwood::save_yaml_obj config, filename, false, true rescue StandardError => e $stderr.puts "warning: #{e.message}" end diff --git a/lib/sup/source.rb b/lib/sup/source.rb index 9c398f7..f2379fb 100644 --- a/lib/sup/source.rb +++ b/lib/sup/source.rb @@ -212,13 +212,7 @@ class SourceManager def save_sources fn=Redwood::SOURCE_FN @source_mutex.synchronize do if @sources_dirty - bakfn = fn + ".bak" - if File.exists? fn - File.chmod 0600, fn - FileUtils.mv fn, bakfn, :force => true unless File.exists?(bakfn) && File.size(fn) == 0 - end - Redwood::save_yaml_obj sources, fn, true - File.chmod 0600, fn + Redwood::save_yaml_obj sources, fn, false, true end @sources_dirty = false end -- 1.7.2.3 _______________________________________________ Sup-devel mailing list Sup-devel@rubyforge.org http://rubyforge.org/mailman/listinfo/sup-devel