s/exists?/symlink?/ + remove useless check + remove useless call to a function.
parent
d29b29bc1b
commit
2a71254533
|
@ -19,11 +19,12 @@ class DODB::Index(V) < DODB::Indexer(V)
|
|||
|
||||
symlink = file_path_index index_key.to_s
|
||||
|
||||
# FIXME: Check it’s not pointing to “old_value”, if any, before raising.
|
||||
if ::File.exists? symlink
|
||||
if ::File.symlink? symlink
|
||||
# In case both old and new values are pointing to the same key,
|
||||
# this is not considered a collision.
|
||||
if old_value
|
||||
old_key = key_proc.call old_value
|
||||
return if symlink == file_path_index old_key.to_s
|
||||
return if index_key == old_key
|
||||
end
|
||||
|
||||
raise IndexOverload.new "index '#{@name}' is overloaded for key '#{key}', file #{symlink} exists"
|
||||
|
@ -39,11 +40,6 @@ class DODB::Index(V) < DODB::Indexer(V)
|
|||
|
||||
Dir.mkdir_p ::File.dirname symlink
|
||||
|
||||
# FIXME: Now that this is done in check!, can we remove it?
|
||||
if ::File.exists? symlink
|
||||
raise Exception.new "symlink already exists: #{symlink}"
|
||||
end
|
||||
|
||||
::File.symlink get_data_symlink_index(key), symlink
|
||||
end
|
||||
|
||||
|
@ -96,9 +92,7 @@ class DODB::Index(V) < DODB::Indexer(V)
|
|||
|
||||
def get_key_on_fs(index : String) : Int32
|
||||
file_path = file_path_index index
|
||||
|
||||
raise MissingEntry.new(@name, index) unless ::File.exists? file_path
|
||||
|
||||
raise MissingEntry.new(@name, index) unless ::File.symlink? file_path
|
||||
::File.readlink(file_path).sub(/^.*\//, "").to_i
|
||||
end
|
||||
|
||||
|
@ -158,8 +152,9 @@ class DODB::CachedIndex(V) < DODB::Index(V)
|
|||
def check!(key, value, old_value)
|
||||
index_key = key_proc.call value
|
||||
|
||||
# FIXME: Check it’s not pointing to “old_value”, if any, before raising.
|
||||
if data[index_key]?
|
||||
# In case both old and new values are pointing to the same key,
|
||||
# this is not considered a collision.
|
||||
if old_value
|
||||
old_key = key_proc.call old_value
|
||||
return if index_key == old_key
|
||||
|
|
Loading…
Reference in New Issue