Fix static analysys
This commit is contained in:
parent
1de5b8db5a
commit
a689a220d3
7 changed files with 19 additions and 25 deletions
|
@ -24,7 +24,7 @@ module Gitlab
|
|||
|
||||
def chunks_count(job_id)
|
||||
Gitlab::Redis::Cache.with do |redis|
|
||||
redis.scan_each(:match => buffer_key(job_id, '?')).inject(0) do |sum, key|
|
||||
redis.scan_each(match: buffer_key(job_id, '?')).inject(0) do |sum, key|
|
||||
sum + 1
|
||||
end
|
||||
end
|
||||
|
@ -32,15 +32,15 @@ module Gitlab
|
|||
|
||||
def chunks_size(job_id)
|
||||
Gitlab::Redis::Cache.with do |redis|
|
||||
redis.scan_each(:match => buffer_key(job_id, '?')).inject(0) do |sum, key|
|
||||
sum += redis.strlen(key)
|
||||
redis.scan_each(match: buffer_key(job_id, '?')).inject(0) do |sum, key|
|
||||
sum + redis.strlen(key)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def delete_all(job_id)
|
||||
Gitlab::Redis::Cache.with do |redis|
|
||||
redis.scan_each(:match => buffer_key(job_id, '?')) do |key|
|
||||
redis.scan_each(match: buffer_key(job_id, '?')) do |key|
|
||||
redis.del(key)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -189,10 +189,10 @@ module Gitlab
|
|||
|
||||
chunk_store.open(job_id, chunk_index, params_for_store) do |store|
|
||||
with_callbacks(:write_chunk, store) do
|
||||
written_size = if buffer_size == data.length || store.size == 0
|
||||
store.write!(data)
|
||||
else
|
||||
written_size = if store.size > 0 # # rubocop:disable ZeroLengthPredicate
|
||||
store.append!(data)
|
||||
else
|
||||
store.write!(data)
|
||||
end
|
||||
|
||||
raise WriteError, 'Written size mismatch' unless data.length == written_size
|
||||
|
|
|
@ -7,27 +7,26 @@ module Gitlab
|
|||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
class_attribute :_before_callbacks, :_after_callbacks,
|
||||
:instance_writer => false
|
||||
class_attribute :_before_callbacks, :_after_callbacks, instance_writer: false
|
||||
self._before_callbacks = Hash.new []
|
||||
self._after_callbacks = Hash.new []
|
||||
end
|
||||
|
||||
def with_callbacks(kind, *args)
|
||||
self.class._before_callbacks[kind].each { |c| send c, *args }
|
||||
self.class._before_callbacks[kind].each { |c| send c, *args } # rubocop:disable GitlabSecurity/PublicSend
|
||||
yield
|
||||
self.class._after_callbacks[kind].each { |c| send c, *args }
|
||||
self.class._after_callbacks[kind].each { |c| send c, *args } # rubocop:disable GitlabSecurity/PublicSend
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
def before_callback(kind, callback)
|
||||
self._before_callbacks = self._before_callbacks.
|
||||
merge kind => _before_callbacks[kind] + [callback]
|
||||
self._before_callbacks = self._before_callbacks
|
||||
.merge kind => _before_callbacks[kind] + [callback]
|
||||
end
|
||||
|
||||
def after_callback(kind, callback)
|
||||
self._after_callbacks = self._after_callbacks.
|
||||
merge kind => _after_callbacks[kind] + [callback]
|
||||
self._after_callbacks = self._after_callbacks
|
||||
.merge kind => _after_callbacks[kind] + [callback]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,7 +8,6 @@ module Gitlab
|
|||
|
||||
included do
|
||||
WriteError = Class.new(StandardError)
|
||||
FailedToGetChunkError = Class.new(StandardError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,12 +6,10 @@ module Gitlab
|
|||
module Permissions
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
WRITABLE_MODE = %w[a]
|
||||
READABLE_MODE = %w[r +]
|
||||
WRITABLE_MODE = %w[a].freeze
|
||||
READABLE_MODE = %w[r +].freeze
|
||||
|
||||
included do
|
||||
PermissionError = Class.new(StandardError)
|
||||
|
||||
attr_reader :write_lock_uuid
|
||||
end
|
||||
|
||||
|
@ -20,7 +18,7 @@ module Gitlab
|
|||
@write_lock_uuid = Gitlab::ExclusiveLease
|
||||
.new(write_lock_key(job_id), timeout: 1.hour.to_i).try_obtain
|
||||
|
||||
raise PermissionError, 'Already opened by another process' unless write_lock_uuid
|
||||
raise IOError, 'Already opened by another process' unless write_lock_uuid
|
||||
end
|
||||
|
||||
super
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
include ActionDispatch::TestProcess
|
||||
|
||||
FactoryBot.define do
|
||||
factory :job_trace_chunk, class: Ci::JobTraceChunk do
|
||||
factory :ci_job_trace_chunk, class: Ci::JobTraceChunk do
|
||||
job factory: :ci_build
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@ describe Gitlab::Ci::Trace::ChunkedFile::LiveTrace, :clean_gitlab_redis_cache do
|
|||
|
||||
let(:chunk_stores) do
|
||||
[Gitlab::Ci::Trace::ChunkedFile::ChunkStore::Redis,
|
||||
Gitlab::Ci::Trace::ChunkedFile::ChunkStore::Database]
|
||||
Gitlab::Ci::Trace::ChunkedFile::ChunkStore::Database]
|
||||
end
|
||||
|
||||
describe 'ChunkStores are Redis and Database', :partial_support do
|
||||
|
|
Loading…
Reference in a new issue