-
Notifications
You must be signed in to change notification settings - Fork 164
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
iterate over directory and delete files no longer works #288
Comments
I don't think this code is correct. The fixed code would increment the iterator before removing the file. Additionally, if the increment throws, the iterator may become an end iterator, which you should check in the
That said, the original code does not have to fail because the implementation is allowed to cache some information in the |
… dir_it. This commit changes behavior of directory_entry constructors and modifiers that change the stored path: the methods will now automatically query the filesystem for the file status instead of leaving the cached data default-initialized. This means that the paths passed to directory_entry must be valid, otherwise an error will be returned. Filesystem querying is implemented in the new directory_entry::refresh methods. The constructors and modifiers that accepted file_status arguments are now marked deprecated. The cached file statuses are an implementation detail, and eventually we may want to add more cached data, as we add more observers to directory_entry. Also added a few file type observers to directory_entry. These observers allow to avoid querying the filesystem if the full file status is not cached but the file type is (i.e. when permissions are not cached). This is the case with readdir-based implementation of directory_iterator, if the underlying C library supports dirent::d_type field. recursive_directory_iterator has been updated to use the added file type observers instead of querying the full status. This may improve performance of directory iteration. Closes #288.
Thanks a lot for your help. I have changed my code to increment the iterator first and it works nicely now. |
I am using boost::filesystem to loop over files in a directory and conditionally delete them. It works in boost 1.71 but in boost 1.74 it crashes after the first file has been deleted. Is this a bug or am I doing something wrong? What is the recommended way to iterate over a directory and delete files?
main.cpp:
The text was updated successfully, but these errors were encountered: