Commit a689a220 authored by Shinya Maeda's avatar Shinya Maeda

Fix static analysys

parent 1de5b8db
...@@ -24,7 +24,7 @@ module Gitlab ...@@ -24,7 +24,7 @@ module Gitlab
def chunks_count(job_id) def chunks_count(job_id)
Gitlab::Redis::Cache.with do |redis| 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 sum + 1
end end
end end
...@@ -32,15 +32,15 @@ module Gitlab ...@@ -32,15 +32,15 @@ module Gitlab
def chunks_size(job_id) def chunks_size(job_id)
Gitlab::Redis::Cache.with do |redis| 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 += redis.strlen(key) sum + redis.strlen(key)
end end
end end
end end
def delete_all(job_id) def delete_all(job_id)
Gitlab::Redis::Cache.with do |redis| 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) redis.del(key)
end end
end end
......
...@@ -189,10 +189,10 @@ module Gitlab ...@@ -189,10 +189,10 @@ module Gitlab
chunk_store.open(job_id, chunk_index, params_for_store) do |store| chunk_store.open(job_id, chunk_index, params_for_store) do |store|
with_callbacks(:write_chunk, store) do with_callbacks(:write_chunk, store) do
written_size = if buffer_size == data.length || store.size == 0 written_size = if store.size > 0 # # rubocop:disable ZeroLengthPredicate
store.write!(data)
else
store.append!(data) store.append!(data)
else
store.write!(data)
end end
raise WriteError, 'Written size mismatch' unless data.length == written_size raise WriteError, 'Written size mismatch' unless data.length == written_size
......
...@@ -7,27 +7,26 @@ module Gitlab ...@@ -7,27 +7,26 @@ module Gitlab
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do included do
class_attribute :_before_callbacks, :_after_callbacks, class_attribute :_before_callbacks, :_after_callbacks, instance_writer: false
:instance_writer => false
self._before_callbacks = Hash.new [] self._before_callbacks = Hash.new []
self._after_callbacks = Hash.new [] self._after_callbacks = Hash.new []
end end
def with_callbacks(kind, *args) 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 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 end
module ClassMethods module ClassMethods
def before_callback(kind, callback) def before_callback(kind, callback)
self._before_callbacks = self._before_callbacks. self._before_callbacks = self._before_callbacks
merge kind => _before_callbacks[kind] + [callback] .merge kind => _before_callbacks[kind] + [callback]
end end
def after_callback(kind, callback) def after_callback(kind, callback)
self._after_callbacks = self._after_callbacks. self._after_callbacks = self._after_callbacks
merge kind => _after_callbacks[kind] + [callback] .merge kind => _after_callbacks[kind] + [callback]
end end
end end
end end
......
...@@ -8,7 +8,6 @@ module Gitlab ...@@ -8,7 +8,6 @@ module Gitlab
included do included do
WriteError = Class.new(StandardError) WriteError = Class.new(StandardError)
FailedToGetChunkError = Class.new(StandardError)
end end
end end
end end
......
...@@ -6,12 +6,10 @@ module Gitlab ...@@ -6,12 +6,10 @@ module Gitlab
module Permissions module Permissions
extend ActiveSupport::Concern extend ActiveSupport::Concern
WRITABLE_MODE = %w[a] WRITABLE_MODE = %w[a].freeze
READABLE_MODE = %w[r +] READABLE_MODE = %w[r +].freeze
included do included do
PermissionError = Class.new(StandardError)
attr_reader :write_lock_uuid attr_reader :write_lock_uuid
end end
...@@ -20,7 +18,7 @@ module Gitlab ...@@ -20,7 +18,7 @@ module Gitlab
@write_lock_uuid = Gitlab::ExclusiveLease @write_lock_uuid = Gitlab::ExclusiveLease
.new(write_lock_key(job_id), timeout: 1.hour.to_i).try_obtain .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 end
super super
......
include ActionDispatch::TestProcess
FactoryBot.define do FactoryBot.define do
factory :job_trace_chunk, class: Ci::JobTraceChunk do factory :ci_job_trace_chunk, class: Ci::JobTraceChunk do
job factory: :ci_build job factory: :ci_build
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment