Merge branch '2061-update-docs'
[arvados.git] / services / api / app / models / collection.rb
index 99510449fe31193253c62ff057c883df4aa8e7ea..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.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'
@@ -63,6 +65,14 @@ class Collection < ArvadosModel
     @files = []
     manifest_text.split("\n").each do |stream|
       toks = stream.split(" ")
+
+      stream = toks[0].gsub /\\(\\|[0-7]{3})/ do |escape_sequence|
+        case $1
+        when '\\' '\\'
+        else $1.to_i(8).chr
+        end
+      end
+
       toks[1..-1].each do |tok|
         if (re = tok.match /^[0-9a-f]{32}/)
           blocksize = nil
@@ -84,7 +94,7 @@ class Collection < ArvadosModel
               else $1.to_i(8).chr
               end
             end
-            @files << [toks[0], filename, re[2].to_i]
+            @files << [stream, filename, re[2].to_i]
           end
         end
       end