New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gracefully handle unreadable directories #86

merged 3 commits into from Aug 22, 2018


None yet
2 participants

owst commented Aug 18, 2018

If there is an unreadable directory considered by ripper-tags, an exception is raised:

.../lib/ripper-tags/data_reader.rb:59:in `open': Permission denied @ dir_initialize - foo/bar (Errno::EACCES)
	from .../lib/ripper-tags/data_reader.rb:59:in `entries'
	from .../lib/ripper-tags/data_reader.rb:59:in `resolve_file'
	from .../lib/ripper-tags/data_reader.rb:63:in `block in resolve_file'

(tested with 0.6.0)

This PR gracefully handles such directories, by skipping them (and logging if --verbose is given).

To reproduce the existing behaviour, run:

$ mkdir -p a/b
$ touch a/b/c.rb
$ chmod 355 a/b
$ ripper-tags --tag-file=/dev/null --recursive --verbose a # Errors

with this PR, we now have

$ bundle exec bin/ripper-tags --tag-file=/dev/null --recursive --verbose a
Ignoring unreadable directory `a/b'

Nice catch! Thank you for handling this.

@@ -75,6 +71,21 @@ def resolve_file(file, depth = 0, &block)
def resolve_files_in_directory(directory, depth, &block)
unless File.readable?(directory)

This comment has been minimized.


mislav Aug 20, 2018


Instead of checking File.readable? could we handle an exception from Dir.entries?

This comment has been minimized.


owst Aug 21, 2018


Thanks for the review - sure, I've pushed a fixup to do that

owst and others added some commits Aug 18, 2018

Simplify skipping unreadable directories
The `rescue Errno::EACCES` clause now only applies to `Dir.entries()`
call and not to the yielded block.

@mislav mislav force-pushed the owst:handle_unreadable_directories branch from 209f8f7 to 131dbcf Aug 22, 2018


mislav approved these changes Aug 22, 2018

@mislav mislav merged commit bcc3b1b into tmm1:master Aug 22, 2018

1 check was pending

continuous-integration/travis-ci/pr The Travis CI build is in progress
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment