Harden RecursiveDirectoryIterator when walking the filesystem.#530
Closed
mjdorma wants to merge 4 commits intopocoproject:developfrom
Closed
Harden RecursiveDirectoryIterator when walking the filesystem.#530mjdorma wants to merge 4 commits intopocoproject:developfrom
mjdorma wants to merge 4 commits intopocoproject:developfrom
Conversation
…rforms an unguarded list directory. If the directory is not accessible an unrecoverable error is raised thus ruining the walk. This changeset adopts and adapts the error handling protocol as defined in Python's os.walk function where errors from listdir are ignored or are reported to an optional on error callback function.
Author
|
For sure, I'll give it a go... Cheers! |
…tor behaviour over unreadable directories.
…tor behaviour over unreadable directories. Correct bad formatting
Author
|
Hi @aleks-f , In the above change set I have included two testcases to exercise the error callback code for both iteration strategies. The tests are exercised in completeness under UNIX. As you will see I have included a posix implementation of a local static function called setReadable. Thanks for the great set of libraries. Cheers |
Member
|
Instead of setOnError(), could you use a |
Member
|
@mjdorma what is the status of this? |
Member
|
@mkrivos : can you look at this? |
Member
Member
|
done in #2001 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In the implementation for the *Traverse strategies the next method performs an unguarded list directory. If the directory is not accessible an unrecoverable error is raised thus ruining the walk. This changeset adopts and adapts the error handling protocol as defined in Python's os.walk function where errors from listdir are ignored or are reported to an optional on error callback function.
Building a unittest to demonstrate this issue did not seem feasible as it would require the test program to contain privileges necessary to alter the access permissions of a directory then setuid to an alternative user.
To exercise this error condition I defined a folder structure as follows:
I then added the following functions to the Foundation testsuite DirectoryIteratorsTest:
When ran:
Desired result achieved.