Created
February 10, 2009 18:32
-
-
Save wuputah/61521 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
tmp_file_path('gateway', '/data/nginx_tmp') |
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
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