From 7a46fa387227fa422cf90adc14c5f84ac57454ea Mon Sep 17 00:00:00 2001 From: Luka Vandervelden Date: Wed, 20 Nov 2019 00:32:32 +0100 Subject: [PATCH] get_nn_partition returns an empty array if no key has been indexed. --- src/fs.cr | 3 +++ test-nn.cr | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/fs.cr b/src/fs.cr index 8711281..444e64c 100644 --- a/src/fs.cr +++ b/src/fs.cr @@ -80,6 +80,9 @@ class FS::Hash(K, V) r_value = Array(V).new partition_directory = "#{dir_path_nn name}/#{key}" + + return r_value unless Dir.exists? partition_directory + Dir.each_child partition_directory do |child| r_value << V.from_json ::File.read "#{partition_directory}/#{child}" end diff --git a/test-nn.cr b/test-nn.cr index 0187900..b1a7973 100644 --- a/test-nn.cr +++ b/test-nn.cr @@ -55,3 +55,7 @@ s.to_h.size.times do pp! s.get_nn_partition("tags", "shiratsuyu").map &.title end +puts "Testing get_nn_partition on unknown entries." + +pp! s.get_nn_partition("tags", "kaga").map &.title +