Merge branch 'master' into 6234-user-edit-self
[arvados.git] / services / api / app / models / collection.rb
index bbced41537fa99199918589bb79444d6a9d3fea8..cac25d1c537981a433db526f730957f943c0d487 100644 (file)
@@ -9,6 +9,7 @@ class Collection < ArvadosModel
   serialize :properties, Hash
 
   before_validation :check_encoding
+  before_validation :log_invalid_manifest_format
   before_validation :check_signatures
   before_validation :strip_signatures_and_update_replication_confirmed
   validate :ensure_pdh_matches_manifest_text
@@ -62,8 +63,10 @@ class Collection < ArvadosModel
         now: db_current_time.to_i,
       }
       self.manifest_text.each_line do |entry|
-        entry.split[1..-1].each do |tok|
-          if tok =~ FILE_TOKEN
+        entry.split.each do |tok|
+          if tok == '.' or tok.starts_with? './'
+            # Stream name token.
+          elsif tok =~ FILE_TOKEN
             # This is a filename token, not a blob locator. Note that we
             # keep checking tokens after this, even though manifest
             # format dictates that all subsequent tokens will also be
@@ -190,6 +193,15 @@ class Collection < ArvadosModel
     end
   end
 
+  def log_invalid_manifest_format
+    begin
+      Keep::Manifest.validate! manifest_text if manifest_text
+    rescue => e
+      logger.warn e
+    end
+    true
+  end
+
   def signed_manifest_text
     if has_attribute? :manifest_text
       token = current_api_client_authorization.andand.api_token
@@ -220,7 +232,9 @@ class Collection < ArvadosModel
       line.rstrip!
       new_words = []
       line.split(' ').each do |word|
-        if match = Keep::Locator::LOCATOR_REGEXP.match(word)
+        if new_words.empty?
+          new_words << word
+        elsif match = Keep::Locator::LOCATOR_REGEXP.match(word)
           new_words << yield(match)
         else
           new_words << word