Skip to content

Instantly share code, notes, and snippets.

@robey
Created February 1, 2009 05:28
Show Gist options
  • Save robey/55796 to your computer and use it in GitHub Desktop.
Save robey/55796 to your computer and use it in GitHub Desktop.
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