From b7a73e8f98def13b527259817b8c274f3b92707c Mon Sep 17 00:00:00 2001 From: Trey Pendragon Date: Fri, 15 Sep 2023 09:44:46 -0700 Subject: [PATCH] Check for path existence in case test suite runs too fast. --- lib/valkyrie/storage/versioned_disk.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/valkyrie/storage/versioned_disk.rb b/lib/valkyrie/storage/versioned_disk.rb index 5ac053f3..1ab5e278 100644 --- a/lib/valkyrie/storage/versioned_disk.rb +++ b/lib/valkyrie/storage/versioned_disk.rb @@ -21,13 +21,16 @@ def initialize(base_path:, path_generator: ::Valkyrie::Storage::Disk::BucketedSt def upload(file:, original_filename:, resource: nil, **_extra_arguments) version_timestamp = current_timestamp new_path = path_generator.generate(resource: resource, file: file, original_filename: "v-#{version_timestamp}-#{original_filename}") + # If we've gone faster than milliseconds here, re-call. Probably only an + # issue for test suites. + return upload(file: file, original_filename: original_filename, resource: resource, **_extra_arguments) if File.exist?(new_path) FileUtils.mkdir_p(new_path.parent) file_mover.call(file.try(:path) || file.try(:disk_path), new_path) find_by(id: Valkyrie::ID.new("versiondisk://#{new_path}")) end def current_timestamp - Time.now.strftime("%s%N") + Time.now.strftime("%s%L") end def upload_version(id:, file:) @@ -37,6 +40,8 @@ def upload_version(id:, file:) current_version_id = current_version_id.version_files[1] if current_version_id.deletion_marker? existing_path = current_version_id.file_path new_path = Pathname.new(existing_path.gsub(current_version_id.version, version_timestamp.to_s)) + # If we've gone faster than milliseconds here, re-call. + return upload_version(id: id, file: file) if File.exist?(new_path) FileUtils.mkdir_p(new_path.parent) file_mover.call(file.try(:path) || file.try(:disk_path), new_path) find_by(id: Valkyrie::ID.new("versiondisk://#{new_path}"))