From 89d1768f87e1195fb87a0d431588b4491434bbde Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Wed, 6 May 2015 14:56:12 +0200 Subject: [PATCH] Corrected with rubocop cop 'Lint/UselessAccessModifier'. --- .rubocop.yml | 2 - app/models/avatar.rb | 2 - app/models/history.rb | 2 - app/models/link.rb | 2 - app/models/recent_view.rb | 2 - app/models/store/provider/file.rb | 88 +++++++++++++------------------ app/models/tag.rb | 2 - lib/search_index_backend.rb | 2 - lib/user_agent.rb | 2 - 9 files changed, 37 insertions(+), 67 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index dab552a55..c1851aab5 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -226,8 +226,6 @@ Style/RedundantSelf: Enabled: false Style/Next: Enabled: false -Lint/UselessAccessModifier: - Enabled: false Style/CommentIndentation: Enabled: false Metrics/CyclomaticComplexity: diff --git a/app/models/avatar.rb b/app/models/avatar.rb index 2607c9f1d..2b6287205 100644 --- a/app/models/avatar.rb +++ b/app/models/avatar.rb @@ -336,8 +336,6 @@ returns: ).first end - private - def self.set_default_items(object_id, o_id, avatar_id) avatars = Avatar.where( object_lookup_id: object_id, diff --git a/app/models/history.rb b/app/models/history.rb index 9dfcf2c52..0526bb93b 100644 --- a/app/models/history.rb +++ b/app/models/history.rb @@ -213,8 +213,6 @@ returns list end - private - def self.type_lookup_id( id ) # use cache diff --git a/app/models/link.rb b/app/models/link.rb index 2c541da3d..57377ec82 100644 --- a/app/models/link.rb +++ b/app/models/link.rb @@ -151,8 +151,6 @@ class Link < ApplicationModel } end - private - def self.link_type_get(data) linktype = Link::Type.where( name: data[:name] ).first if !linktype diff --git a/app/models/recent_view.rb b/app/models/recent_view.rb index 5db403034..06a550d0b 100644 --- a/app/models/recent_view.rb +++ b/app/models/recent_view.rb @@ -83,8 +83,6 @@ class RecentView < ApplicationModel ) end - private - def self.access(object, o_id, user) # check if object exists diff --git a/app/models/store/provider/file.rb b/app/models/store/provider/file.rb index 0ce1b614b..01551b506 100644 --- a/app/models/store/provider/file.rb +++ b/app/models/store/provider/file.rb @@ -3,21 +3,53 @@ class Store::Provider::File + # write file to fs def self.add(data, sha) - write_to_fs(data, sha) + + # install file + permission = '600' + if !File.exist?( get_locaton(sha) ) + Rails.logger.debug "storge write '#{ get_locaton(sha) }' (#{permission})" + file = File.new( get_locaton(sha), 'wb' ) + file.write( data ) + file.close + end + File.chmod( permission.to_i(8), get_locaton(sha) ) + + # check sha + local_sha = Digest::SHA256.hexdigest( get(sha) ) + if sha != local_sha + raise "ERROR: Corrupt file in fs #{ get_locaton(sha) }, sha should be #{sha} but is #{local_sha}" + end + true end + # read file from fs def self.get(sha) - read_from_fs(sha) + Rails.logger.debug "read from fs #{ get_locaton(sha) }" + if !File.exist?( get_locaton(sha) ) + raise "ERROR: No such file #{ get_locaton(sha) }" + end + data = File.open( get_locaton(sha), 'rb' ) + content = data.read + + # check sha + local_sha = Digest::SHA256.hexdigest( content ) + if local_sha != sha + raise "ERROR: Corrupt file in fs #{ get_locaton(sha) }, sha should be #{sha} but is #{local_sha}" + end + content end + # unlink file from fs def self.delete(sha) - unlink_from_fs(sha) + if File.exist?( get_locaton(sha) ) + Rails.logger.info "storge remove '#{ get_locaton(sha) }'" + File.delete( get_locaton(sha) ) + end end - private - # generate file location def self.get_locaton(sha) @@ -35,50 +67,4 @@ class Store::Provider::File location += file end - # unlink file from fs - def self.unlink_from_fs(sha) - if File.exist?( get_locaton(sha) ) - Rails.logger.info "storge remove '#{ get_locaton(sha) }'" - File.delete( get_locaton(sha) ) - end - end - - # read file from fs - def self.read_from_fs(sha) - Rails.logger.debug "read from fs #{ get_locaton(sha) }" - if !File.exist?( get_locaton(sha) ) - raise "ERROR: No such file #{ get_locaton(sha) }" - end - data = File.open( get_locaton(sha), 'rb' ) - content = data.read - - # check sha - local_sha = Digest::SHA256.hexdigest( content ) - if local_sha != sha - raise "ERROR: Corrupt file in fs #{ get_locaton(sha) }, sha should be #{sha} but is #{local_sha}" - end - content - end - - # write file to fs - def self.write_to_fs(data, sha) - - # install file - permission = '600' - if !File.exist?( get_locaton(sha) ) - Rails.logger.debug "storge write '#{ get_locaton(sha) }' (#{permission})" - file = File.new( get_locaton(sha), 'wb' ) - file.write( data ) - file.close - end - File.chmod( permission.to_i(8), get_locaton(sha) ) - - # check sha - local_sha = Digest::SHA256.hexdigest( read_from_fs(sha) ) - if sha != local_sha - raise "ERROR: Corrupt file in fs #{ get_locaton(sha) }, sha should be #{sha} but is #{local_sha}" - end - - true - end end diff --git a/app/models/tag.rb b/app/models/tag.rb index 9f2b30cd7..4878167fb 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -62,8 +62,6 @@ class Tag < ApplicationModel tags end - private - def self.tag_item_lookup_id( id ) # use cache diff --git a/lib/search_index_backend.rb b/lib/search_index_backend.rb index 78f7fbb82..a70600e8e 100644 --- a/lib/search_index_backend.rb +++ b/lib/search_index_backend.rb @@ -244,8 +244,6 @@ return true if backend is configured true end - private - def self.build_url( type = nil, o_id = nil ) return if !SearchIndexBackend.enabled? index = Setting.get('es_index').to_s + "_#{Rails.env}" diff --git a/lib/user_agent.rb b/lib/user_agent.rb index 3878306f5..814fce72f 100644 --- a/lib/user_agent.rb +++ b/lib/user_agent.rb @@ -240,8 +240,6 @@ returns end - private - def self.get_http(uri, options) http = Net::HTTP.new(uri.host, uri.port)