mktemp: handle dirs with restricted permissions
This commit is contained in:
parent
a96e364b41
commit
a6e7858cbc
@ -62,9 +62,23 @@ class Mktemp
|
|||||||
begin
|
begin
|
||||||
Dir.chdir(tmpdir) { yield self }
|
Dir.chdir(tmpdir) { yield self }
|
||||||
ensure
|
ensure
|
||||||
ignore_interrupts { rm_rf(tmpdir) } unless retain?
|
ignore_interrupts { chmod_rm_rf(tmpdir) } unless retain?
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
ohai "Temporary files retained at:", @tmpdir.to_s if retain? && !@tmpdir.nil? && !@quiet
|
ohai "Temporary files retained at:", @tmpdir.to_s if retain? && !@tmpdir.nil? && !@quiet
|
||||||
end
|
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
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user