Skip to content
Open
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
23 changes: 23 additions & 0 deletions lib/omnibus/file_syncer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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