diff options
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/projects/hashed_storage/migrate_repository_service.rb | 28 | ||||
-rw-r--r-- | app/services/projects/hashed_storage/rollback_repository_service.rb | 28 |
2 files changed, 46 insertions, 10 deletions
diff --git a/app/services/projects/hashed_storage/migrate_repository_service.rb b/app/services/projects/hashed_storage/migrate_repository_service.rb index fd62ac37d27..adc7e38e4d5 100644 --- a/app/services/projects/hashed_storage/migrate_repository_service.rb +++ b/app/services/projects/hashed_storage/migrate_repository_service.rb @@ -21,14 +21,32 @@ module Projects project.storage_version = nil end - project.repository_read_only = false - project.save!(validate: false) - - if result && block_given? - yield + project.transaction do + project.save!(validate: false) + project.set_repository_writable! end result + rescue Gitlab::Git::CommandError => e + logger.error("Repository #{project.full_path} failed to upgrade (PROJECT_ID=#{project.id}). Git operation failed: #{e.inspect}") + + rollback_migration! + + false + rescue OpenSSL::Cipher::CipherError => e + logger.error("Repository #{project.full_path} failed to upgrade (PROJECT_ID=#{project.id}). There is a problem with encrypted attributes: #{e.inspect}") + + rollback_migration! + + false + end + + private + + def rollback_migration! + rollback_folder_move + project.storage_version = nil + project.set_repository_writable! end end end diff --git a/app/services/projects/hashed_storage/rollback_repository_service.rb b/app/services/projects/hashed_storage/rollback_repository_service.rb index d6646e3765e..6ab49630603 100644 --- a/app/services/projects/hashed_storage/rollback_repository_service.rb +++ b/app/services/projects/hashed_storage/rollback_repository_service.rb @@ -21,14 +21,32 @@ module Projects project.storage_version = ::Project::HASHED_STORAGE_FEATURES[:repository] end - project.repository_read_only = false - project.save!(validate: false) - - if result && block_given? - yield + project.transaction do + project.save!(validate: false) + project.set_repository_writable! end result + rescue Gitlab::Git::CommandError => e + logger.error("Repository #{project.full_path} failed to rollback (PROJECT_ID=#{project.id}). Git operation failed: #{e.inspect}") + + rollback_migration! + + false + rescue OpenSSL::Cipher::CipherError => e + logger.error("Repository #{project.full_path} failed to rollback (PROJECT_ID=#{project.id}). There is a problem with encrypted attributes: #{e.inspect}") + + rollback_migration! + + false + end + + private + + def rollback_migration! + rollback_folder_move + project.storage_version = ::Project::HASHED_STORAGE_FEATURES[:repository] + project.set_repository_writable! end end end |