Skip to content

Commit

Permalink
Fix #18 - crashing when removing directories with nested paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Maher4Ever committed Apr 13, 2012
1 parent d0bcb2d commit 5478732
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/listen/directory_record.rb
Expand Up @@ -169,6 +169,9 @@ def detect_modifications_and_removals(directory, options = {})
# @option options [Boolean] relative_paths whether or not to use relative paths for changes
#
def detect_additions(directory, options = {})
# Don't process removed directories
return unless File.exist?(directory)

Find.find(directory) do |path|
next if path == @directory

Expand Down
17 changes: 17 additions & 0 deletions spec/listen/directory_record_spec.rb
Expand Up @@ -747,6 +747,23 @@
@record.paths["#{path}/a_directory"]['file.rb'].should be_nil
end
end

context 'with nested paths' do
it 'detects removals without crashing - #18', :focus do
fixtures do |path|
mkdir_p 'a_directory/b_directory'
touch 'a_directory/b_directory/do_not_use.rb'

modified, added, removed = changes(path, :paths => [path, "#{path}/a_directory", "#{path}/b_directory"]) do
rm_r 'a_directory'
end

added.should be_empty
modified.should be_empty
removed.should =~ %w(a_directory/b_directory/do_not_use.rb)
end
end
end
end

context 'with a path outside the directory for which a record is made' do
Expand Down

0 comments on commit 5478732

Please sign in to comment.