-
Notifications
You must be signed in to change notification settings - Fork 64
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
Add list_files filtering #106
Conversation
088d2ca
to
4c82719
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
4c82719
to
3815c3c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
@@ -229,20 +230,32 @@ std::string get_absolute_path(const std::string& path) | |||
return full; | |||
} | |||
|
|||
paths list_files(const std::string& path) | |||
paths list_files(const std::string& path, ItemType filter, const std::string& match) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: function 'list_files' defined in a header file; function definitions in header files can lead to ODR violations [misc-definitions-in-headers]
paths list_files(const std::string& path, ItemType filter, const std::string& match)
^
Additional context
base/fs_unix.h:232: make as 'inline'
paths list_files(const std::string& path, ItemType filter, const std::string& match)
^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Just minor changes about indentation (probably when the const
keyword was removed).
// Item types that list_files() can be filtered by | ||
enum class ItemType { | ||
All, | ||
Directories, | ||
Files | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if using flags might simplify the code (minor change: fixed the indentation):
// Item types that list_files() can be filtered by | |
enum class ItemType { | |
All, | |
Directories, | |
Files | |
}; | |
// Item types that list_files() can be filtered by | |
enum class ItemType { | |
Directories = 1, | |
Files = 2, | |
All = 3 | |
}; | |
LAF_ENUM_FLAGS(ItemType); |
The LAF_ENUM_FLAGS
macro is something new to make flags easier to use for enum class
-type (you will need to rebase to the latest main to use this macro if you wish).
Anyway this change is not needed, we can use the ItemType
as you've defined it, just fixing the indentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'll keep a simple enum class since you can't really mix and match flags in this case, if you want Directories | Files you use "All", and if you want Directories | All... you... well you shouldn't want that, that makes no sense 🤪
As part of my work on #4610 I've added directory/file filtering and pattern matching to
base::list_files
and made some optimizations and other changes:FindFirstFileEx
on Windows which has flags to get directories directly and returns a more basic structure.fnmatch
on Unix to replicate the wildcard matching Windows behaviorThis allows us to use list_files much more efficiently, since before you had to do:
which caused file attributes to be fetched twice, once when listing and another time when calling
is_file
, resulting in double the amount of IO operations. Now we can now just do:which is faster, and IMO more ergonomic.
I'll be working on a PR to modify aseprite to take advantage of this next, figured we can be getting the benefits of what I'm doing for the "recent files" fix and it'll make that easier to review.
There's a couple of things for which I'd like your opinion @dacap: