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
|
def atomic_write content
|
||||||
require "tempfile"
|
require "tempfile"
|
||||||
tf = Tempfile.new(basename.to_s, dirname)
|
tf = Tempfile.new(basename.to_s, dirname)
|
||||||
tf.binmode
|
|
||||||
tf.write(content)
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
old_stat = stat
|
tf.binmode
|
||||||
rescue Errno::ENOENT
|
tf.write(content)
|
||||||
old_stat = default_stat
|
|
||||||
|
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
|
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
|
end
|
||||||
|
|
||||||
def default_stat
|
def default_stat
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user