From 351df7426f251a20e000169b0b1dd394314e197f Mon Sep 17 00:00:00 2001 From: Philippe PITTOLI Date: Tue, 7 May 2024 00:03:07 +0200 Subject: [PATCH] Fix partition implementation. --- src/dodb/partition.cr | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/dodb/partition.cr b/src/dodb/partition.cr index 41e7a0e..53d68e1 100644 --- a/src/dodb/partition.cr +++ b/src/dodb/partition.cr @@ -36,7 +36,10 @@ class DODB::Partition(V) < DODB::Indexer(V) symlink = get_partition_symlink(partition, key) - ::File.delete symlink + begin + ::File.delete symlink + rescue File::NotFoundError + end end def get(partition) : Array(V) @@ -128,11 +131,11 @@ class DODB::CachedPartition(V) < DODB::Partition(V) end def get(partition) - r_value = Array(V).new + r_value = Array(Tuple(V, Int32)).new if keys = @data[partition]? keys.each do |data_key| - r_value << @storage[data_key] + r_value << { @storage[data_key], data_key } end else # Get the key from the database representation on the file-system. @@ -140,10 +143,11 @@ class DODB::CachedPartition(V) < DODB::Partition(V) raise MissingEntry.new(@name, partition) unless Dir.exists? partition_directory Dir.each_child partition_directory do |child| - r_value << @storage[get_key child] + r_value << { @storage[get_key child], get_key child } end - @data[partition] = r_value + + @data[partition] = r_value.map &.[1] end - r_value + r_value.map &.[0] end end