Skip to content

Commit

Permalink
Fix unintended amalgamation of root files and the directory list
Browse files Browse the repository at this point in the history
  • Loading branch information
driskell authored and e2 committed May 6, 2015
1 parent e639493 commit c6bb44f
Showing 1 changed file with 14 additions and 28 deletions.
42 changes: 14 additions & 28 deletions lib/listen/record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize(listener)
end

def add_dir(dir, rel_path)
return if [nil, '', '.'].include? rel_path
rel_path = '.' if [nil, '', '.'].include? rel_path
@paths[dir.to_s][rel_path] ||= {}
end

Expand All @@ -32,23 +32,16 @@ def unset_path(dir, rel_path)
def file_data(dir, rel_path)
root = @paths[dir.to_s]
dirname, basename = Pathname(rel_path).split.map(&:to_s)
if [nil, '', '.'].include? dirname
root[basename] ||= {}
root[basename].dup
else
root[dirname] ||= {}
root[dirname][basename] ||= {}
root[dirname][basename].dup
end
dirname = '.' if [nil, '', '.'].include? dirname
root[dirname] ||= {}
root[dirname][basename] ||= {}
root[dirname][basename].dup
end

def dir_entries(dir, rel_path)
tree = if [nil, '', '.'].include? rel_path.to_s
@paths[dir.to_s]
else
@paths[dir.to_s][rel_path.to_s] ||= _auto_hash
@paths[dir.to_s][rel_path.to_s]
end
rel_path = '.' if [nil, '', '.'].include? rel_path.to_s
@paths[dir.to_s][rel_path.to_s] ||= _auto_hash
tree = @paths[dir.to_s][rel_path.to_s]

result = {}
tree.each do |key, values|
Expand Down Expand Up @@ -81,25 +74,18 @@ def _auto_hash

def _fast_update_file(dir, dirname, basename, data)
root = @paths[dir.to_s]
if [nil, '', '.'].include? dirname
root[basename] = (root[basename] || {}).merge(data)
else
root[dirname] ||= {}
root[dirname][basename] = (root[dirname][basename] || {}).merge(data)
end
dirname = '.' if [nil, '', '.'].include? dirname
root[dirname] ||= {}
root[dirname][basename] = (root[dirname][basename] || {}).merge(data)
end

def _fast_unset_path(dir, dirname, basename)
root = @paths[dir.to_s]
# this may need to be reworked to properly remove
# entries from a tree, without adding non-existing dirs to the record
if [nil, '', '.'].include? dirname
return unless root.key?(basename)
root.delete(basename)
else
return unless root.key?(dirname)
root[dirname].delete(basename)
end
dirname = '.' if [nil, '', '.'].include? dirname
return unless root.key?(dirname)
root[dirname].delete(basename)
end

# TODO: test with a file name given
Expand Down

0 comments on commit c6bb44f

Please sign in to comment.