mktemp: handle dirs with restricted permissions
This commit is contained in:
parent
a96e364b41
commit
a6e7858cbc
@ -62,9 +62,23 @@ class Mktemp
|
||||
begin
|
||||
Dir.chdir(tmpdir) { yield self }
|
||||
ensure
|
||||
ignore_interrupts { rm_rf(tmpdir) } unless retain?
|
||||
ignore_interrupts { chmod_rm_rf(tmpdir) } unless retain?
|
||||
end
|
||||
ensure
|
||||
ohai "Temporary files retained at:", @tmpdir.to_s if retain? && !@tmpdir.nil? && !@quiet
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def chmod_rm_rf(path)
|
||||
if path.directory? && !path.symlink?
|
||||
chmod("u+rw", path) if path.owned? # Need permissions in order to see the contents
|
||||
path.children.each { |child| chmod_rm_rf(child) }
|
||||
rmdir(path)
|
||||
else
|
||||
rm_f(path)
|
||||
end
|
||||
rescue
|
||||
nil # Just skip this directory.
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user