Pull initialization code out of begin block
This commit is contained in:
parent
b34fa6cfd8
commit
0578f1ff5a
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user