aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMax Howell2010-05-10 01:10:49 +0100
committerAdam Vandenberg2011-03-12 11:55:04 -0800
commitd3b41f29e190c0c13c0ec80b59c56a0dcfe4666c (patch)
tree5a27a1a28640b638fb6357bbdedb7f94b6538fef /Library
parenta28e4d89c52cefee700c96a701b9b4051c035857 (diff)
downloadhomebrew-d3b41f29e190c0c13c0ec80b59c56a0dcfe4666c.tar.bz2
Pathname.ensure_writable
Yields after chmoding (if necessary), once block is complete restores permissions.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/extend/pathname.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb
index 8b690a258..5534cd752 100644
--- a/Library/Homebrew/extend/pathname.rb
+++ b/Library/Homebrew/extend/pathname.rb
@@ -238,6 +238,16 @@ class Pathname
def / that
join that.to_s
end
+
+ def ensure_writable
+ saved_perms = unless writable?
+ chmod 0644
+ stat.mode
+ end
+ yield
+ ensure
+ chmod saved_perms if saved_perms
+ end
end
# sets $n and $d so you can observe creation of stuff