Pull initialization code out of begin block

This commit is contained in:
Jack Nagel 2014-11-09 18:17:10 -06:00
parent b34fa6cfd8
commit 0578f1ff5a

View File

@ -106,27 +106,29 @@ class Pathname
def atomic_write content
require "tempfile"
tf = Tempfile.new(basename.to_s, dirname)
tf.binmode
tf.write(content)
begin
old_stat = stat
rescue Errno::ENOENT
old_stat = default_stat
tf.binmode
tf.write(content)
begin
old_stat = stat
rescue Errno::ENOENT
old_stat = default_stat
end
uid = Process.uid
gid = Process.groups.delete(old_stat.gid) { Process.gid }
begin
tf.chown(uid, gid)
tf.chmod(old_stat.mode)
rescue Errno::EPERM
end
File.rename(tf.path, self)
ensure
tf.close!
end
uid = Process.uid
gid = Process.groups.delete(old_stat.gid) { Process.gid }
begin
tf.chown(uid, gid)
tf.chmod(old_stat.mode)
rescue Errno::EPERM
end
File.rename(tf.path, self)
ensure
tf.close!
end
def default_stat