5179: update files method to move dir parts to streamname.
authorRadhika Chippada <radhika@curoverse.com>
Sun, 19 Apr 2015 02:22:14 +0000 (22:22 -0400)
committerRadhika Chippada <radhika@curoverse.com>
Sun, 19 Apr 2015 02:22:14 +0000 (22:22 -0400)
sdk/ruby/lib/arvados/keep.rb
sdk/ruby/test/sdk_fixtures.rb
sdk/ruby/test/test_keep_manifest.rb

index e4f62083b0d5568d757d8ae05dc043170e10f6ca..a1f418b2b5b6eb5756695e078e77cd88256b06cb 100644 (file)
@@ -165,6 +165,11 @@ module Keep
       if @files.nil?
         file_sizes = Hash.new(0)
         each_file_spec do |streamname, _, filesize, filename|
+          if filename.include?('/')
+            parts = filename.rpartition('/')
+            streamname = streamname + parts[1] + parts[0]   # ./dir_parts
+            filename = parts[2]
+          end
           file_sizes[[streamname, filename]] += filesize
         end
         @files = file_sizes.each_pair.map do |(streamname, filename), size|
index 52d7377f80c7ae41889353fe0a7507e950ff43c5..80dfabfdebb317b7451476bff392e57ca18cf94b 100644 (file)
@@ -54,6 +54,8 @@ module SDKFixtures
   NONNORMALIZED_MANIFEST =
     ["./dir2 #{random_block} 0:0:z 0:0:y 0:0:x",
      "./dir1 #{random_block} 0:0:p 0:0:o 0:0:n\n"].join("\n")
+  MULTILEVEL_MANIFEST_WITH_DIRS_IN_FILENAMES =
+    [". #{random_block(10)} 0:3:file1 3:3:dir1/file1 6:3:dir1/dir2/file1\n"].join("")
 
   ### Non-tree manifests
   # These manifests follow the spec, but they express a structure that can't
index f1f1a530ceddbf35a9d5cd3066acc180eb4f254e..18b58ca9a1845e0ba04bc0db617142a7063f8888 100644 (file)
@@ -208,4 +208,22 @@ class ManifestTest < Minitest::Test
       assert !file_name.empty?, "empty file_name in #{name} fixture"
     end
   end
+
+  def test_multilevel_collection_with_dirs_in_filenames
+    manifest = Keep::Manifest.new(MULTILEVEL_MANIFEST_WITH_DIRS_IN_FILENAMES)
+
+    seen = Hash.new { |this, key| this[key] = [] }
+
+    manifest.files.each do |stream, basename, size|
+      refute(seen[stream].include?(basename), "each_file repeated #{stream}/#{basename}")
+      assert_equal(3, size, "wrong size for #{stream}/#{basename}")
+      seen[stream] << basename
+    end
+
+    assert_equal(%w(. ./dir1 ./dir1/dir2), seen.keys)
+
+    seen.each_pair do |stream, basenames|
+      assert_equal(%w(file1), basenames.sort, "wrong file list for #{stream}")
+    end
+  end
 end