From 123f7cd00e490bf91d4272b3d4a12041ab3bc4fe Mon Sep 17 00:00:00 2001 From: Max Howell Date: Mon, 10 May 2010 01:10:49 +0100 Subject: [PATCH] Pathname.ensure_writable Yields after chmoding (if necessary), once block is complete restores permissions. --- Library/Homebrew/extend/pathname.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index 8b690a2581..5534cd7528 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