Safely escaping and reading back a file path in ruby
- by user336851
I need to save a few informations about some files. Nothing too fancy so I thought I would go with a simple one line per item text file. Something like this :
# write
io.print "%i %s %s\n" % [File.mtime(fname), fname, Digest::SHA1.file(fname).hexdigest]
# read
io.each do |line|
mtime, name, hash = line.scanf "%i %s %s"
end
Of course this…