Skip to content

Instantly share code, notes, and snippets.

@wuputah
Created February 10, 2009 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wuputah/61521 to your computer and use it in GitHub Desktop.
Save wuputah/61521 to your computer and use it in GitHub Desktop.
tmp_file_path('gateway', '/data/nginx_tmp')
require 'fcntl'
def tmp_file_path(prefix, base_path)
while true
random_string = prefix + Array.new(16) { rand(256) }.pack('C*').unpack('H*').first
begin
fh = File.open(File.join(base_path, random_string), Fcntl::O_EXCL | Fcntl::O_CREAT | Fcntl::O_WRONLY)
fh.close
return File.join(base_path, random_string)
rescue Errno::EEXIST
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment