Merge branch '11510-sdk-extend-files' refs #11510
[arvados.git] / apps / workbench / app / controllers / collections_controller.rb
index 701b590bcbb8a49c152a8c04e2455aa207724486..dc9ed43c409b64a2838ad74d3e165609c49e1e62 100644 (file)
@@ -1,4 +1,5 @@
 require "arvados/keep"
+require "arvados/collection"
 require "uri"
 
 class CollectionsController < ApplicationController
@@ -308,19 +309,6 @@ class CollectionsController < ApplicationController
     end
   end
 
-  def rename_selected_file
-    arv_coll = Arv::Collection.new(@object.manifest_text)
-    source_paths[uuids[0]].each do |p|
-      arv_coll.rename "./"+params[:src], "./"+params[:dst]
-    end
-
-    if @object.update_attributes manifest_text: arv_coll.manifest_text
-      show
-    else
-      self.render_error status: 422
-    end
-  end
-
   def update
     updated_attr = params[:collection].each.select {|a| a[0].andand.start_with? 'rename-file-path:'}
 
@@ -338,15 +326,21 @@ class CollectionsController < ApplicationController
       end
 
       arv_coll = Arv::Collection.new(@object.manifest_text)
-      arv_coll.rename "./"+file_path, new_file_path
 
-      if @object.update_attributes manifest_text: arv_coll.manifest_text
-        show
-      else
+      if arv_coll.exist?(new_file_path)
+        @errors = 'Duplicate file path. Please use a different name.'
         self.render_error status: 422
+      else
+        arv_coll.rename "./"+file_path, new_file_path
+
+        if @object.update_attributes manifest_text: arv_coll.manifest_text
+          show
+        else
+          self.render_error status: 422
+        end
       end
     else
-      # Non a file rename; use default
+      # Not a file rename; use default
       super
     end
   end