bagit-python
bagit-python copied to clipboard
Improve permission check performance
I saw a "TODO" in the code regarding a redundant os.walk operation when checking whether a Bag can actually be created or not, which this pull request addresses.
I've combined _can_bag and _can_read into one function that walk()s through the bag directory at most once (instead of twice). Additionally, I am raising an exception when an unreadable/unwriteable file/dir is encountered. This is opposed to the previous method of compiling a complete list of all unreadable/unwriteable items, printing them, and then throwing an exception. The offending file name is now included in the exception rather than returned in a tuple.