From c01df40abf08a13dd10868ccd0de6314788c1f55 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 2 May 2014 11:03:06 +0200 Subject: [PATCH] Added self.fs_check_md5(). --- app/models/store.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/models/store.rb b/app/models/store.rb index c73da9129..9d69e21e1 100644 --- a/app/models/store.rb +++ b/app/models/store.rb @@ -45,6 +45,8 @@ returns md5 = Digest::MD5.hexdigest( data['data'] ) data['size'] = data['data'].to_s.bytesize + # file = Store::Provider::DB.create( data['data'], md5 ) + file = Store::File.where( :md5 => md5 ).first # store attachment @@ -126,6 +128,7 @@ returns # check backend for references files = Store.where( :store_file_id => store.store_file_id ) if files.count == 1 && files.first.id == store.id + # file = Store::Provider::DB.delete( store.store_file_id ) Store::File.find( store.store_file_id ).destroy end @@ -136,6 +139,7 @@ returns # get attachment def content + # Store::Provider::DB.content( store.store_file_id ) file = Store::File.where( :id => self.store_file_id ).first return if !file if file.file_system @@ -249,6 +253,19 @@ class Store::File < ApplicationModel true end + def self.fs_check_md5(fix_it = nil) + Store::File.where( :file_system => true ).each {|item| + md5 = Digest::MD5.hexdigest( item.read_from_fs ) + 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 Store::File.where( :file_system => false ).each {|item| item.write_to_fs