From 93ccdfb0e66f69d0439e96c53574b71838727145 Mon Sep 17 00:00:00 2001 From: Celian Raimbault Date: Tue, 25 Mar 2025 10:03:32 +0100 Subject: [PATCH 1/2] [fix-git-race-condition] Fix --- lib/omnibus/file_syncer.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/omnibus/file_syncer.rb b/lib/omnibus/file_syncer.rb index e3ab57bed..0b2513d81 100644 --- a/lib/omnibus/file_syncer.rb +++ b/lib/omnibus/file_syncer.rb @@ -123,15 +123,21 @@ def sync(source, destination, options = {}) "the `copy' method instead." end + wait_git_operations() + source_files = all_files_under(source, options) # Ensure the destination directory exists create_sync_dir(source, destination) + wait_git_operations() + # Clear any hardlink that we might have seen while syncing a previous directory # This can happen when generating 2 different packages in a row hardlink_sources.clear + wait_git_operations() + # Copy over the filtered source files source_files.each do |source_file| relative_path = relative_path_for(source_file, source) @@ -263,5 +269,22 @@ def create_sync_dir(source, destination) end end end + + # + # Wait for any git operation to finish and avoid temporary files + # being removed between file syncing operations + # + def wait_git_operations() + puts "CELIAN Waiting for temporary files" + + # For each index.lock file, wait for it to be removed + Dir.glob("**/.git/index.lock").each do |file| + puts "CELIAN Found `#{file}' temporary file" + # Wait for the lock file to be removed + while File.exist?(file) + sleep 0.05 + end + end + end end end From e1e2dd97a554f112283f09c5b503ca51b5f6b91c Mon Sep 17 00:00:00 2001 From: Celian Raimbault Date: Wed, 7 May 2025 14:09:24 +0200 Subject: [PATCH 2/2] [fix-git-race-condition] Added id --- lib/omnibus/file_syncer.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/omnibus/file_syncer.rb b/lib/omnibus/file_syncer.rb index 0b2513d81..4829b3ace 100644 --- a/lib/omnibus/file_syncer.rb +++ b/lib/omnibus/file_syncer.rb @@ -123,20 +123,20 @@ def sync(source, destination, options = {}) "the `copy' method instead." end - wait_git_operations() + wait_git_operations(1) source_files = all_files_under(source, options) # Ensure the destination directory exists create_sync_dir(source, destination) - wait_git_operations() + wait_git_operations(2) # Clear any hardlink that we might have seen while syncing a previous directory # This can happen when generating 2 different packages in a row hardlink_sources.clear - wait_git_operations() + wait_git_operations(3) # Copy over the filtered source files source_files.each do |source_file| @@ -274,8 +274,8 @@ def create_sync_dir(source, destination) # Wait for any git operation to finish and avoid temporary files # being removed between file syncing operations # - def wait_git_operations() - puts "CELIAN Waiting for temporary files" + def wait_git_operations(id) + puts "CELIAN Waiting for temporary files #{id}" # For each index.lock file, wait for it to be removed Dir.glob("**/.git/index.lock").each do |file|