Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/cli_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,6 @@ jobs:
--id "com.emerge-cli.integration" \
--repo-name "EmergeTools/emerge-cli" \
--debug \
--profile \
--batch \
test/fixtures/snapshots
29 changes: 20 additions & 9 deletions lib/commands/upload/snapshots/snapshots.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module EmergeCLI
VERSION = '0.7.1'.freeze
VERSION = '0.7.2'.freeze
end