Improved splitting of file name.

This commit is contained in:
Martin Edenhofer 2014-04-28 21:20:09 +02:00
parent 4b35e77104
commit 5a5168aa5e

View file

@ -158,15 +158,17 @@ class Store::File < ApplicationModel
def get_locaton def get_locaton
# generate directory # generate directory
base = Rails.root.to_s + "/storage/fs/" base = Rails.root.to_s + '/storage/fs/'
path = self.md5.scan(/.../).join('/') parts = self.md5.scan(/.{1,3}/)
path = parts[ 1 .. 7 ].join('/') + '/'
file = parts[ 8 .. parts.count ].join('')
location = "#{base}/#{path}" location = "#{base}/#{path}"
# create directory if not exists # create directory if not exists
if !File.exist?( location ) if !File.exist?( location )
FileUtils.mkdir_p( location ) FileUtils.mkdir_p( location )
end end
location += "/file" location += file
end end
# read file from fs # read file from fs
@ -233,6 +235,20 @@ class Store::File < ApplicationModel
true true
end end
# check database data and md5, in case fix it
def self.db_check_md5(fix_it = nil)
Store::File.where( :file_system => false ).each {|item|
md5 = Digest::MD5.hexdigest( item.data )
if md5 != item.md5
puts "DIFF: md5 diff of Store::File.find(#{item.id}) "
if fix_it
item.update_attribute( :md5, md5 )
end
end
}
true
end
def self.move_to_fs def self.move_to_fs
Store::File.where( :file_system => false ).each {|item| Store::File.where( :file_system => false ).each {|item|
item.write_to_fs item.write_to_fs