7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/asset_cloud/free_key_locator.rb', line 7
def find_free_key_like(key, options = {})
if !options[:force_uuid] && !exist?(key)
key
else
ext = File.extname(key)
dirname = File.dirname(key)
base = dirname == "." ? File.basename(key, ext) : File.join(File.dirname(key), File.basename(key, ext))
base = base.gsub(/_[\h]{8}-[\h]{4}-4[\h]{3}-[\h]{4}-[\h]{12}/, "")
key = "#{base}_#{SecureRandom.uuid}#{ext}"
return key unless exist?(key)
raise StandardError, "Filesystem out of free filenames"
end
end
|