diff --git a/app/services/site_service.rb b/app/services/site_service.rb index 5522245a..90a4a339 100644 --- a/app/services/site_service.rb +++ b/app/services/site_service.rb @@ -90,9 +90,13 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do def rename(name) Site.transaction do site.name = name - FileUtils.mv site.path_was, site.path(name: name) + raise ActiveRecord::Rollback if File.exists?(name) + FileUtils.mv site.path_was, site.path unless File.exists?(name) ActiveStorage::Blob.where(service_name: site.name_was).update_all(service_name: site.name) site.save + rescue StandardError + FileUtils.mv site.path, site.path_was if File.exists?(name) + raise end end