File tree 7 files changed +43
-85
lines changed
7 files changed +43
-85
lines changed Original file line number Diff line number Diff line change @@ -98,3 +98,35 @@ auto rlib::zstd_frame_decompress_size(std::span<char const> src) -> std::size_t
98
98
rlib_assert_zstd (ZSTD_getFrameHeader (&header, src.data (), src.size ()));
99
99
return header.frameContentSize ;
100
100
}
101
+
102
+ auto rlib::collect_files (std::vector<std::string> const & inputs, function_ref<bool (fs::path const & path)> filter)
103
+ -> std::vector<fs::path> {
104
+ auto paths = std::vector<fs::path>{};
105
+ if (inputs.size () == 1 && inputs.back () == " -" ) {
106
+ std::string line;
107
+ while (std::getline (std::cin, line)) {
108
+ if (line.empty ()) {
109
+ continue ;
110
+ }
111
+ paths.push_back (line);
112
+ }
113
+ } else {
114
+ for (auto const & input : inputs) {
115
+ rlib_assert (fs::exists (input));
116
+ if (fs::is_regular_file (input)) {
117
+ paths.push_back (input);
118
+ } else {
119
+ for (auto const & entry : fs::directory_iterator (input)) {
120
+ if (!entry.is_regular_file ()) {
121
+ continue ;
122
+ }
123
+ if (filter && !filter (entry.path ())) {
124
+ continue ;
125
+ }
126
+ paths.push_back (entry.path ());
127
+ }
128
+ }
129
+ }
130
+ }
131
+ return paths;
132
+ }
Original file line number Diff line number Diff line change 7
7
#include < cinttypes>
8
8
#include < cstddef>
9
9
#include < cstring>
10
+ #include < filesystem>
10
11
#include < functional>
11
12
#include < optional>
12
13
#include < span>
54
55
}()
55
56
56
57
namespace rlib {
58
+ namespace fs = std::filesystem;
59
+
57
60
[[noreturn]] extern void throw_error (char const * from, char const * msg);
58
61
59
62
[[noreturn]] inline void throw_error (char const * from, std::error_code const & ec) {
@@ -155,4 +158,7 @@ namespace rlib {
155
158
Ret (*invoke_)(void * ref, Args...) = nullptr ;
156
159
void * ref_ = nullptr ;
157
160
};
161
+
162
+ extern auto collect_files (std::vector<std::string> const & inputs, function_ref<bool (fs::path const & path)> filter)
163
+ -> std::vector<fs::path>;
158
164
}
Original file line number Diff line number Diff line change @@ -39,24 +39,8 @@ struct Main {
39
39
}
40
40
41
41
auto run () -> void {
42
- auto paths = std::vector<fs::path>();
43
42
std::cerr << " Collecting input bundles ... " << std::endl;
44
- for (auto const & input : cli.inputs ) {
45
- rlib_assert (fs::exists (input));
46
- if (fs::is_regular_file (input)) {
47
- paths.push_back (input);
48
- } else {
49
- for (auto const & entry : fs::directory_iterator (input)) {
50
- if (!entry.is_regular_file ()) {
51
- continue ;
52
- }
53
- if (entry.path ().extension () != " .bundle" ) {
54
- continue ;
55
- }
56
- paths.push_back (entry.path ());
57
- }
58
- }
59
- }
43
+ auto paths = collect_files (cli.inputs , [](fs::path const & p) { return p.extension () == " .bundle" ; });
60
44
std::cerr << " Processing input bundles ... " << std::endl;
61
45
for (std::uint32_t index = paths.size (); auto const & path : paths) {
62
46
verify_bundle (path, index --);
Original file line number Diff line number Diff line change @@ -48,24 +48,8 @@ struct Main {
48
48
}
49
49
50
50
auto run () -> void {
51
- auto paths = std::vector<fs::path>();
52
51
std::cerr << " Collecting input bundles ... " << std::endl;
53
- for (auto const & input : cli.inputs ) {
54
- rlib_assert (fs::exists (input));
55
- if (fs::is_regular_file (input)) {
56
- paths.push_back (input);
57
- } else {
58
- for (auto const & entry : fs::directory_iterator (input)) {
59
- if (!entry.is_regular_file ()) {
60
- continue ;
61
- }
62
- if (entry.path ().extension () != " .bundle" ) {
63
- continue ;
64
- }
65
- paths.push_back (entry.path ());
66
- }
67
- }
68
- }
52
+ auto paths = collect_files (cli.inputs , [](fs::path const & p) { return p.extension () == " .bundle" ; });
69
53
if (!paths.empty () && !cli.force ) {
70
54
std::cerr << " Processing existing chunks ... " << std::endl;
71
55
fs::create_directories (cli.output );
Original file line number Diff line number Diff line change @@ -29,24 +29,8 @@ struct Main {
29
29
}
30
30
31
31
auto run () -> void {
32
- auto paths = std::vector<fs::path>();
33
32
std::cerr << " Collecting input bundles ... " << std::endl;
34
- for (auto const & input : cli.inputs ) {
35
- rlib_assert (fs::exists (input));
36
- if (fs::is_regular_file (input)) {
37
- paths.push_back (input);
38
- } else {
39
- for (auto const & entry : fs::directory_iterator (input)) {
40
- if (!entry.is_regular_file ()) {
41
- continue ;
42
- }
43
- if (entry.path ().extension () != " .bundle" ) {
44
- continue ;
45
- }
46
- paths.push_back (entry.path ());
47
- }
48
- }
49
- }
33
+ auto paths = collect_files (cli.inputs , [](fs::path const & p) { return p.extension () == " .bundle" ; });
50
34
std::cerr << " Processing input bundles ... " << std::endl;
51
35
for (auto const & path : paths) {
52
36
list_bundle (path);
Original file line number Diff line number Diff line change @@ -51,24 +51,8 @@ struct Main {
51
51
}
52
52
53
53
auto run () {
54
- auto paths = std::vector<fs::path>();
55
54
std::cerr << " Collecting input bundles ... " << std::endl;
56
- for (auto const & input : cli.inputs ) {
57
- rlib_assert (fs::exists (input));
58
- if (fs::is_regular_file (input)) {
59
- paths.push_back (input);
60
- } else {
61
- for (auto const & entry : fs::directory_iterator (input)) {
62
- if (!entry.is_regular_file ()) {
63
- continue ;
64
- }
65
- if (entry.path ().extension () != " .bundle" ) {
66
- continue ;
67
- }
68
- paths.push_back (entry.path ());
69
- }
70
- }
71
- }
55
+ auto paths = collect_files (cli.inputs , [](fs::path const & p) { return p.extension () == " .bundle" ; });
72
56
if (paths.empty ()) {
73
57
return ;
74
58
}
Original file line number Diff line number Diff line change @@ -30,24 +30,8 @@ struct Main {
30
30
}
31
31
32
32
auto run () -> void {
33
- auto paths = std::vector<fs::path>();
34
33
std::cerr << " Collecting input bundles ... " << std::endl;
35
- for (auto const & input : cli.inputs ) {
36
- rlib_assert (fs::exists (input));
37
- if (fs::is_regular_file (input)) {
38
- paths.push_back (input);
39
- } else {
40
- for (auto const & entry : fs::directory_iterator (input)) {
41
- if (!entry.is_regular_file ()) {
42
- continue ;
43
- }
44
- if (entry.path ().extension () != " .bundle" ) {
45
- continue ;
46
- }
47
- paths.push_back (entry.path ());
48
- }
49
- }
50
- }
34
+ auto paths = collect_files (cli.inputs , [](fs::path const & p) { return p.extension () == " .bundle" ; });
51
35
std::cerr << " Processing input bundles ... " << std::endl;
52
36
for (auto const & path : paths) {
53
37
process_bundle (path);
You can’t perform that action at this time.
0 commit comments