]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | /* |
2 | * This file is open source software, licensed to you under the terms | |
3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file | |
4 | * distributed with this work for additional information regarding copyright | |
5 | * ownership. You may not use this file except in compliance with the License. | |
6 | * | |
7 | * You may obtain a copy of the License at | |
8 | * | |
9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
10 | * | |
11 | * Unless required by applicable law or agreed to in writing, | |
12 | * software distributed under the License is distributed on an | |
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
14 | * KIND, either express or implied. See the License for the | |
15 | * specific language governing permissions and limitations | |
16 | * under the License. | |
17 | */ | |
18 | /* | |
19 | * Copyright (C) 2014 Cloudius Systems, Ltd. | |
20 | */ | |
21 | ||
22 | ||
23 | #include <seastar/core/reactor.hh> | |
24 | #include <seastar/core/app-template.hh> | |
25 | #include <seastar/core/print.hh> | |
26 | #include <seastar/core/shared_ptr.hh> | |
27 | ||
28 | using namespace seastar; | |
29 | ||
9f95a23c TL |
30 | const char* de_type_desc(directory_entry_type t) |
31 | { | |
32 | switch (t) { | |
33 | case directory_entry_type::unknown: | |
34 | return "unknown"; | |
35 | case directory_entry_type::block_device: | |
36 | return "block_device"; | |
37 | case directory_entry_type::char_device: | |
38 | return "char_device"; | |
39 | case directory_entry_type::directory: | |
40 | return "directory"; | |
41 | case directory_entry_type::fifo: | |
42 | return "fifo"; | |
43 | case directory_entry_type::link: | |
44 | return "link"; | |
45 | case directory_entry_type::regular: | |
46 | return "regular"; | |
47 | case directory_entry_type::socket: | |
48 | return "socket"; | |
49 | } | |
50 | assert(0 && "should not get here"); | |
51 | return nullptr; | |
52 | } | |
53 | ||
11fdf7f2 TL |
54 | int main(int ac, char** av) { |
55 | class lister { | |
56 | file _f; | |
57 | subscription<directory_entry> _listing; | |
58 | public: | |
59 | lister(file f) | |
60 | : _f(std::move(f)) | |
61 | , _listing(_f.list_directory([this] (directory_entry de) { return report(de); })) { | |
62 | } | |
63 | future<> done() { return _listing.done(); } | |
64 | private: | |
65 | future<> report(directory_entry de) { | |
9f95a23c TL |
66 | return file_stat(de.name, follow_symlink::no).then([de = std::move(de)] (stat_data sd) { |
67 | if (de.type) { | |
68 | assert(*de.type == sd.type); | |
69 | } else { | |
70 | assert(sd.type == directory_entry_type::unknown); | |
71 | } | |
72 | fmt::print("{} (type={})\n", de.name, de_type_desc(sd.type)); | |
73 | return make_ready_future<>(); | |
74 | }); | |
11fdf7f2 TL |
75 | } |
76 | }; | |
9f95a23c | 77 | return app_template().run(ac, av, [] { |
11fdf7f2 | 78 | return engine().open_directory(".").then([] (file f) { |
9f95a23c TL |
79 | return do_with(lister(std::move(f)), [] (lister& l) { |
80 | return l.done().then([] { | |
81 | return 0; | |
82 | }); | |
83 | }); | |
11fdf7f2 TL |
84 | }); |
85 | }); | |
86 | } |