Created
February 1, 2009 05:28
-
-
Save robey/55796 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def with_temp_folder(&block) | |
count = 0 | |
begin | |
name = "/tmp/test#{rand(2 ** 32)}" | |
Dir.mkdir(name) | |
rescue SystemCallError | |
retry if count < 10 | |
raise | |
end | |
begin | |
yield name | |
ensure | |
Dir.foreach(name) { |fn| puts fn; File.delete("#{name}/#{fn}") unless [ ".", ".." ].include?(fn) } | |
Dir.rmdir(name) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment