From 56ac16c77870af18f4d9a8299fa3119c85444600 Mon Sep 17 00:00:00 2001 From: Christopher Guess Date: Thu, 17 Oct 2024 16:36:34 +0200 Subject: [PATCH] Fix a bug where no files found would be a divide by zero error --- Gemfile | 1 + Gemfile.lock | 44 +++++++++++++++++++----------------- eikon.gemspec | 3 ++- lib/eikon/version.rb | 2 +- lib/eikon/video_processor.rb | 8 +++++++ 5 files changed, 35 insertions(+), 23 deletions(-) diff --git a/Gemfile b/Gemfile index 63575e2..0363aa6 100644 --- a/Gemfile +++ b/Gemfile @@ -16,6 +16,7 @@ gem "sorbet-static-and-runtime" group :development do gem "tapioca", require: false + gem "pry-byebug" end gem "terrapin" diff --git a/Gemfile.lock b/Gemfile.lock index 6f8073c..43e2a68 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,8 @@ PATH remote: . specs: - eikon (0.1.10) + eikon (0.1.12) + mutex_m ruby-vips (~> 2.1) sorbet-runtime (>= 0.5.9204) terrapin (~> 0.6.0) @@ -29,12 +30,14 @@ GEM tzinfo (~> 2.0) ast (2.4.2) builder (3.2.4) + byebug (11.1.3) climate_control (0.2.0) + coderay (1.1.3) concurrent-ruby (1.1.10) crass (1.0.6) diff-lcs (1.5.0) erubi (1.11.0) - ffi (1.15.5) + ffi (1.16.3) i18n (1.12.0) concurrent-ruby (~> 1.0) json (2.6.2) @@ -44,6 +47,7 @@ GEM method_source (1.0.0) mini_portile2 (2.8.0) minitest (5.16.3) + mutex_m (0.2.0) netrc (0.11.0) nokogiri (1.13.9) mini_portile2 (~> 2.8.0) @@ -51,6 +55,12 @@ GEM parallel (1.22.1) parser (3.1.2.1) ast (~> 2.4.1) + pry (0.14.2) + coderay (~> 1.1) + method_source (~> 1.0) + pry-byebug (3.10.1) + byebug (~> 11.0) + pry (>= 0.13, < 0.15) racc (1.6.0) rack (2.2.4) rack-test (2.0.2) @@ -108,24 +118,15 @@ GEM rubocop-performance (~> 1.11) rubocop-rails (~> 2.0) ruby-progressbar (1.11.0) - ruby-vips (2.1.4) + ruby-vips (2.2.0) ffi (~> 1.12) - sorbet (0.5.10549) - sorbet-static (= 0.5.10549) - sorbet-runtime (0.5.10549) - sorbet-static (0.5.10549-universal-darwin-14) - sorbet-static (0.5.10549-universal-darwin-15) - sorbet-static (0.5.10549-universal-darwin-16) - sorbet-static (0.5.10549-universal-darwin-17) - sorbet-static (0.5.10549-universal-darwin-18) - sorbet-static (0.5.10549-universal-darwin-19) - sorbet-static (0.5.10549-universal-darwin-20) - sorbet-static (0.5.10549-universal-darwin-21) - sorbet-static (0.5.10549-universal-darwin-22) - sorbet-static (0.5.10549-x86_64-linux) - sorbet-static-and-runtime (0.5.10549) - sorbet (= 0.5.10549) - sorbet-runtime (= 0.5.10549) + sorbet (0.5.11604) + sorbet-static (= 0.5.11604) + sorbet-runtime (0.5.11604) + sorbet-static (0.5.11604-universal-darwin) + sorbet-static-and-runtime (0.5.11604) + sorbet (= 0.5.11604) + sorbet-runtime (= 0.5.11604) spoom (1.1.12) sorbet (>= 0.5.9204) sorbet-runtime (>= 0.5.9204) @@ -157,11 +158,12 @@ GEM zeitwerk (2.6.6) PLATFORMS - ruby + arm64-darwin-23 DEPENDENCIES eikon! minitest (~> 5.0) + pry-byebug rake (~> 12.0) rubocop (~> 1.27) rubocop-rails @@ -172,4 +174,4 @@ DEPENDENCIES terrapin BUNDLED WITH - 2.3.11 + 2.5.22 diff --git a/eikon.gemspec b/eikon.gemspec index 2b17c9c..56be650 100644 --- a/eikon.gemspec +++ b/eikon.gemspec @@ -10,7 +10,7 @@ Gem::Specification.new do |spec| spec.description = "A small pure-Ruby (for now) implementation of DHash" spec.homepage = "https://www.github.com/cguess/eikon" spec.license = "MIT" - spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0") + spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0") # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'" @@ -31,4 +31,5 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency "ruby-vips", "~> 2.1" spec.add_runtime_dependency "terrapin", "~> 0.6.0" spec.add_runtime_dependency "sorbet-runtime", ">= 0.5.9204" + spec.add_runtime_dependency "mutex_m" end diff --git a/lib/eikon/version.rb b/lib/eikon/version.rb index 970967d..5b54581 100644 --- a/lib/eikon/version.rb +++ b/lib/eikon/version.rb @@ -1,5 +1,5 @@ # typed: true module Eikon - VERSION = "0.1.11".freeze + VERSION = "0.1.12".freeze end diff --git a/lib/eikon/video_processor.rb b/lib/eikon/video_processor.rb index a20b5f0..5a08d07 100644 --- a/lib/eikon/video_processor.rb +++ b/lib/eikon/video_processor.rb @@ -123,6 +123,14 @@ def remove_blank_shots(folder_path) entry.downcase.end_with?(".jpeg") end + # Somehow there's an emnpty list of files, + # This is going to exclusively be a bug in a different part of the code + # that is using this library, so we'll just make sure we don't break + if file_names.empty? + puts "No files found in the directory. This is likely a bug in the code that called this library." + return + end + # Get the average size of the files total_size = file_names.reduce(0) do |sum, file_name| sum + File.size("#{folder_path}/#{file_name}")