[ARVADOS] updated: 40bbccf9acf872cd610adeb317f06f5ba57504a0
git at public.curoverse.com
git at public.curoverse.com
Tue Jan 6 09:56:31 EST 2015
Summary of changes:
services/api/app/models/collection.rb | 12 +++++++++---
.../api/db/migrate/20141208174653_collection_file_names.rb | 8 +++++++-
services/api/test/unit/collection_test.rb | 13 +++++++++++++
3 files changed, 29 insertions(+), 4 deletions(-)
via 40bbccf9acf872cd610adeb317f06f5ba57504a0 (commit)
from 9b318db813552ab4d3c8e4c904ed32bf03779ef7 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 40bbccf9acf872cd610adeb317f06f5ba57504a0
Author: Radhika Chippada <radhika at curoverse.com>
Date: Tue Jan 6 09:36:49 2015 -0500
4523: extract unique file names from manifest text and set as file_names attribute during save.
diff --git a/services/api/app/models/collection.rb b/services/api/app/models/collection.rb
index 5701a1c..2cbabc3 100644
--- a/services/api/app/models/collection.rb
+++ b/services/api/app/models/collection.rb
@@ -128,9 +128,15 @@ class Collection < ArvadosModel
end
def set_file_names
- if self.manifest_text_changed? and self.manifest_text
- # set file_names to the first 2^16 bytes of manifest_text
- self['file_names'] = self[:manifest_text][0,2**16]
+ if self.manifest_text_changed?
+ file_names = []
+ if self.manifest_text
+ self.manifest_text.split.each do |part|
+ file_name = part.rpartition(':')[-1]
+ file_names << file_name if file_name != '.'
+ end
+ end
+ self.file_names = file_names.uniq.join(" ")[0,2**16]
end
true
end
diff --git a/services/api/db/migrate/20141208174653_collection_file_names.rb b/services/api/db/migrate/20141208174653_collection_file_names.rb
index 20b637c..20c85a1 100644
--- a/services/api/db/migrate/20141208174653_collection_file_names.rb
+++ b/services/api/db/migrate/20141208174653_collection_file_names.rb
@@ -7,7 +7,13 @@ class CollectionFileNames < ActiveRecord::Migration
act_as_system_user do
Collection.all.each do |c|
if c.manifest_text
- c.file_names = c.manifest_text[0, 2**16]
+ file_names = []
+ c.manifest_text.split.each do |part|
+ file_name = part.rpartition(':')[-1]
+ file_names << file_name if file_name != '.'
+ end
+
+ c.file_names = file_names.uniq.join(" ")[0,2**16]
c.save!
end
end
diff --git a/services/api/test/unit/collection_test.rb b/services/api/test/unit/collection_test.rb
index d9c2203..4a14ae8 100644
--- a/services/api/test/unit/collection_test.rb
+++ b/services/api/test/unit/collection_test.rb
@@ -38,4 +38,17 @@ class CollectionTest < ActiveSupport::TestCase
assert_match /UTF-8/, c.errors.messages[:manifest_text].first
end
end
+
+ test 'create and update collection and verify file_names' do
+ act_as_system_user do
+ c = create_collection 'foo', Encoding::US_ASCII
+ assert c.valid?
+ created_file_names = c.file_names
+ assert created_file_names
+
+ c.update_attribute 'manifest_text', ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo2.txt\n"
+ assert_not_equal created_file_names, c.file_names
+ end
+ end
+
end
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list