Skip to content

Commit

Permalink
refactor: simplify some flux pipelines
Browse files Browse the repository at this point in the history
  • Loading branch information
Guekka committed Jul 23, 2024
1 parent 42d9a6f commit ab1c8e5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 21 deletions.
4 changes: 2 additions & 2 deletions cmake/ports/flux/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ vcpkg_from_github(
REPO
tcbrindle/flux
REF
d88fd970d26ec6fc297965ce1dd60b81a5b2def1
d7bbf7c0e895740a05e57e33b5478e12708b219d
SHA512
d390f586d45b69dbad7f8c099382e1bec436b7d864b3797b97c7b69ade7d510c375b763cdd3dbf63356358cc500dad8260df1538e8f0d942119f440ae53f4bd3
b7abe9504784cd6517b2b6bb614ecf95e33d2b1e2c9247a85c0c09bd05c1ed136ea85fd7cad9401f799e85cf99e9d9cff0855557cb1892d8e5dbe7e781a2793f
HEAD_REF
main)

Expand Down
9 changes: 3 additions & 6 deletions src/bsa/pack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,12 @@ struct PackGroup
constexpr std::array allowed_types = {FileTypes::Standard, FileTypes::Texture, FileTypes::Incompressible};

auto packable_files = flux::from_range(fs::recursive_directory_iterator(dir))
.filter([&](const auto &p) { return allow_path_pred(dir, p); })
.filter([&](const auto &p) {
return common::contains(allowed_types, get_filetype(p.path(), dir, sets));
})
.map([](const auto &p) { return p.path(); })
.filter([](const auto &p) {
// filter out empty files
return fs::is_regular_file(p) && fs::file_size(p) > 0;
return p.is_regular_file() && p.file_size() > 0 && allow_path_pred(dir, p)
&& common::contains(allowed_types, get_filetype(p, dir, sets));
})
.map([](const auto &p) { return p.path(); })
.to<std::vector>();

// sort by size, largest first
Expand Down
18 changes: 9 additions & 9 deletions src/bsa/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ const auto k_suffix_separator = std::u8string(u8" - ");
try
{
return flux::from_range(fs::directory_iterator(dir))
.filter([](const auto &f) { return f.is_regular_file(); })
.filter([&sets](const auto &f) {
return common::contains(sets.plugin_extensions,
common::to_lower(f.path().extension().u8string()));
return f.is_regular_file()
&& common::contains(sets.plugin_extensions,
common::to_lower(f.path().extension().u8string()));
})
.map([](const auto &f) { return f.path(); })
.to<std::vector>();
Expand All @@ -40,9 +40,9 @@ const auto k_suffix_separator = std::u8string(u8" - ");
{
const auto raw_suffixes = std::to_array({sets.suffix, sets.texture_suffix});
return flux::ref(raw_suffixes)
// TODO: filter_map
.filter([](const auto &s) { return s.has_value(); })
.map([](const auto &s) { return k_suffix_separator + s.value(); })
.filter_map([](const auto &suffix) {
return suffix.has_value() ? std::optional{k_suffix_separator + suffix.value()} : std::nullopt;
})
.to<std::vector>();
}

Expand Down Expand Up @@ -211,10 +211,10 @@ auto list_archive(const Path &dir, const Settings &sets) noexcept -> std::vector
try
{
std::vector<Path> archives = flux::from_range(fs::directory_iterator(dir))
.filter([](const auto &f) { return f.is_regular_file(); })
.filter([&sets](const auto &f) {
return common::to_lower(f.path().extension().u8string())
== sets.extension;
return f.is_regular_file()
&& common::to_lower(f.path().extension().u8string())
== sets.extension;
})
.map([](const auto &f) { return f.path(); })
.to<std::vector>();
Expand Down
4 changes: 1 addition & 3 deletions src/common/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,12 @@ auto find_matching_paths_icase(const Path &directory,
.to<std::unordered_map<std::u8string, Path>>();

return flux::from(relative_lowercase_paths)
.map([&files_in_directory](const Path &path) -> std::optional<Path> {
.filter_map([&files_in_directory](const Path &path) -> std::optional<Path> {
const auto lower_path = to_lower(path.u8string());
if (const auto it = files_in_directory.find(lower_path); it != files_in_directory.end())
return it->second;
return {};
})
.filter([](const auto &path) { return path.has_value(); })
.map([](const auto &path) { return path.value(); })
.to<std::vector<Path>>();
#endif
}
Expand Down
3 changes: 2 additions & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
"catch2"
]
}
}
},
"builtin-baseline": "f61a294e765b257926ae9e9d85f96468a0af74e7"
}

0 comments on commit ab1c8e5

Please sign in to comment.