Class: File
- Inherits:
-
Object
- Object
- File
- Defined in:
- lib/file_gfdnavi.rb
Constant Summary collapse
- DIR_CHARS =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-."
Class Method Summary collapse
-
.temp_name(path, suffix = nil, length = 32, count = 0) ⇒ Object
alias :_rename :rename private :_rename def rename(from, to) raise(“cannot move file from #from to #to: file #to already exists.”) if File.exist?(to) _rename(from,to) end.
Class Method Details
.temp_name(path, suffix = nil, length = 32, count = 0) ⇒ Object
alias :_rename :rename
private :_rename
def rename(from, to)
raise("cannot move file from #{from} to #{to}: file #{to} already exists.") if File.exist?(to)
_rename(from,to)
end
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/file_gfdnavi.rb', line 15 def temp_name(path, suffix = nil, length = 32, count = 0) path += "/" unless path[-1..-1] == "/" # name = [Digest::MD5.digest(salt)].pack("m").gsub!(/+/,"_").gsub!(/\n/,"").gsub!(/=/,"") name = "" max = DIR_CHARS.length length.times{|i| r = rand(max) name += DIR_CHARS[r..r] } name = path + name name += suffix if suffix if File.exist?(name) if count < 10 return temp_name(path, suffix, length, count+1) else raise "cannot create temporary path name" end end return name end |