diff --git a/lib/omnibus/file_syncer.rb b/lib/omnibus/file_syncer.rb index e3ab57bed..4829b3ace 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(1) + source_files = all_files_under(source, options) # Ensure the destination directory exists create_sync_dir(source, destination) + 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(3) + # 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(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| + 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