From 0578f1ff5a5234a4e7ca59c49dc0b0bb414cb78a Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Sun, 9 Nov 2014 18:17:10 -0600 Subject: Pull initialization code out of begin block --- Library/Homebrew/extend/pathname.rb | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'Library/Homebrew') diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index e65dc25ef..c57f38774 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -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 - end + tf.binmode + tf.write(content) - uid = Process.uid - gid = Process.groups.delete(old_stat.gid) { Process.gid } + begin + old_stat = stat + rescue Errno::ENOENT + old_stat = default_stat + end - begin - tf.chown(uid, gid) - tf.chmod(old_stat.mode) - rescue Errno::EPERM - end + uid = Process.uid + gid = Process.groups.delete(old_stat.gid) { Process.gid } - File.rename(tf.path, self) - ensure - tf.close! + 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 -- cgit v1.2.3