diff --git a/.github/workflows/cli_tests.yml b/.github/workflows/cli_tests.yml index b3fffe1..1415609 100644 --- a/.github/workflows/cli_tests.yml +++ b/.github/workflows/cli_tests.yml @@ -89,4 +89,6 @@ jobs: --id "com.emerge-cli.integration" \ --repo-name "EmergeTools/emerge-cli" \ --debug \ + --profile \ + --batch \ test/fixtures/snapshots diff --git a/lib/commands/upload/snapshots/snapshots.rb b/lib/commands/upload/snapshots/snapshots.rb index 6b7bfeb..07588a4 100644 --- a/lib/commands/upload/snapshots/snapshots.rb +++ b/lib/commands/upload/snapshots/snapshots.rb @@ -68,7 +68,7 @@ def call(image_paths:, **options) image_files = @profiler.measure('find_image_files') { find_image_files(client) } - @profiler.measure('check_duplicate_files') { check_duplicate_files(image_files, client) } + check_duplicate_files(image_files, client) run_id = @profiler.measure('create_run') { create_run } @@ -130,18 +130,26 @@ def find_image_files(client) found_images end - def check_duplicate_files(image_files, client) + def check_duplicate_files(image_files, _client) seen_files = {} + duplicate_files = {} + image_files.each do |image_path| - file_name = client.parse_file_info(image_path)[:file_name] + file_name = File.basename(image_path) if seen_files[file_name] - Logger.warn "Duplicate file name detected: '#{file_name}'. " \ - "Previous occurrence: '#{seen_files[file_name]}'. " \ - 'This upload will overwrite the previous one.' + duplicate_files[file_name] ||= [] + duplicate_files[file_name] << image_path + else + seen_files[file_name] = image_path end - seen_files[file_name] = image_path end + + duplicate_files.each do |filename, paths| + Logger.warn "Found #{paths.length} duplicate(s) of '#{filename}'. Duplicates: #{paths.join(', ')}" + end + + [seen_files, duplicate_files] end def create_run @@ -201,6 +209,8 @@ def batch_upload_images(run_id, image_files, client) errors: [] } + used_filenames, = check_duplicate_files(image_files, client) + @profiler.measure('process_image_metadata') do image_files.each do |image_path| metadata_semaphore.async do @@ -236,8 +246,9 @@ def batch_upload_images(run_id, image_files, client) zipfile.get_output_stream('manifest.json') { |f| f.write(JSON.generate(image_metadata)) } image_files.each do |image_path| - image_name = File.basename(image_path) - zipfile.add(image_name, image_path) + filename = File.basename(image_path) + # Only add files we haven't seen before + zipfile.add(filename, image_path) if used_filenames[filename] == image_path end end end diff --git a/lib/version.rb b/lib/version.rb index 0dd4175..7eb81b8 100644 --- a/lib/version.rb +++ b/lib/version.rb @@ -1,3 +1,3 @@ module EmergeCLI - VERSION = '0.7.1'.freeze + VERSION = '0.7.2'.freeze end