Normalize collection UUID to {hash}+{size} before save and lookup.
authorTom Clegg <tom@curoverse.com>
Mon, 20 Jan 2014 07:34:20 +0000 (23:34 -0800)
committerTom Clegg <tom@curoverse.com>
Mon, 20 Jan 2014 07:52:58 +0000 (23:52 -0800)
refs #1881

services/api/app/controllers/arvados/v1/collections_controller.rb
services/api/app/models/collection.rb

index 4b63747d5b1fe12f78609fe7a6912e51a5404b61..05da5fef0374b5332b487127ec05c6eb38360be5 100644 (file)
@@ -49,4 +49,25 @@ class Arvados::V1::CollectionsController < ApplicationController
     end
     show
   end
     end
     show
   end
+
+  protected
+
+  def find_object_by_uuid
+    super
+    if !@object and !params[:uuid].match(/^[0-9a-f]+\+\d+$/)
+      # Normalize the given uuid and search again.
+      hash_part = params[:uuid].match(/^([0-9a-f]*)/)[1]
+      collection = Collection.where('uuid like ?', hash_part + '+%').first
+      if collection
+        # We know the collection exists, and what its real uuid is in
+        # the database. Now, throw out @objects and repeat the usual
+        # lookup procedure. (Returning the collection at this point
+        # would bypass permission checks.)
+        @objects = nil
+        @where = { uuid: collection.uuid }
+        find_objects_for_index
+        @object = @objects.first
+      end
+    end
+  end
 end
 end
index 863e2cb6b27e903cabdf927c893b453575c64f39..03e5e4ef44c32948e3f923ad3b849f0d71e28c8e 100644 (file)
@@ -28,7 +28,9 @@ class Collection < ArvadosModel
     if self.manifest_text.nil? and self.uuid.nil?
       super
     elsif self.manifest_text and self.uuid
     if self.manifest_text.nil? and self.uuid.nil?
       super
     elsif self.manifest_text and self.uuid
-      if self.uuid.gsub(/\+[^,]+/,'') == Digest::MD5.hexdigest(self.manifest_text)
+      self.uuid.gsub! /\+.*/, ''
+      if self.uuid == Digest::MD5.hexdigest(self.manifest_text)
+        self.uuid.gsub! /$/, '+' + self.manifest_text.length.to_s
         true
       else
         errors.add :uuid, 'uuid does not match checksum of manifest_text'
         true
       else
         errors.add :uuid, 'uuid does not match checksum of manifest_text'