From 12e56dc85dd053c59820b2b38b0803e956d541ad Mon Sep 17 00:00:00 2001 From: Ravi Ranjan Date: Fri, 13 Mar 2026 19:09:17 +0530 Subject: [PATCH] Fix: Handle Userfile rename failures in Controller #1436 --- BrainPortal/app/controllers/userfiles_controller.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/BrainPortal/app/controllers/userfiles_controller.rb b/BrainPortal/app/controllers/userfiles_controller.rb index a3d59e2b0..f71f1138f 100644 --- a/BrainPortal/app/controllers/userfiles_controller.rb +++ b/BrainPortal/app/controllers/userfiles_controller.rb @@ -741,8 +741,11 @@ def update #:nodoc: if @userfile.save_with_logging(current_user, %w( group_writable num_files parent_id hidden ) ) if new_name != old_name - @userfile.provider_rename(new_name) - @userfile.addlog("Renamed by #{current_user.login}: #{old_name} -> #{new_name}") + if @userfile.provider_rename(new_name) + @userfile.addlog("Renamed by #{current_user.login}: #{old_name} -> #{new_name}") + else + @userfile.errors.add(:name, "could not be changed on the storage provider. A file with that name likely already exists.") + end end end end @@ -1117,7 +1120,7 @@ def change_provider #:nodoc: def delete_files #:nodoc: filelist = params[:file_ids] || [] - # Select all accessible files with write acces by the user. + # Select all accessible files with write access by the user. to_delete_ids = Userfile.accessible_for_user(current_user, :access_requested => :write).where(:id => filelist).pluck(:id) not_accessible_count = filelist.size - to_delete_ids.size @@ -1637,7 +1640,7 @@ def extract_from_archive(archive_file_name, file_type = nil, attributes = {}) #: # TODO: FIXME . Not sure how to fix. # # Note on the name of the method: a previous version tried to - # create a symlink structure, but that transferred hte values of + # create a symlink structure, but that transferred the values of # all symbolic links internal to the userfiles on LINUX. # See also: the -H option of tar on MacOS X which would do the trick, # but doesn't exist on LINUX.