diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/seastar/tests/unit/directory_test.cc | |
parent | Initial commit. (diff) | |
download | ceph-upstream.tar.xz ceph-upstream.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/seastar/tests/unit/directory_test.cc')
-rw-r--r-- | src/seastar/tests/unit/directory_test.cc | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/seastar/tests/unit/directory_test.cc b/src/seastar/tests/unit/directory_test.cc new file mode 100644 index 000000000..3f7f540d2 --- /dev/null +++ b/src/seastar/tests/unit/directory_test.cc @@ -0,0 +1,86 @@ +/* + * This file is open source software, licensed to you under the terms + * of the Apache License, Version 2.0 (the "License"). See the NOTICE file + * distributed with this work for additional information regarding copyright + * ownership. You may not use this file except in compliance with the License. + * + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +/* + * Copyright (C) 2014 Cloudius Systems, Ltd. + */ + + +#include <seastar/core/reactor.hh> +#include <seastar/core/app-template.hh> +#include <seastar/core/print.hh> +#include <seastar/core/shared_ptr.hh> + +using namespace seastar; + +const char* de_type_desc(directory_entry_type t) +{ + switch (t) { + case directory_entry_type::unknown: + return "unknown"; + case directory_entry_type::block_device: + return "block_device"; + case directory_entry_type::char_device: + return "char_device"; + case directory_entry_type::directory: + return "directory"; + case directory_entry_type::fifo: + return "fifo"; + case directory_entry_type::link: + return "link"; + case directory_entry_type::regular: + return "regular"; + case directory_entry_type::socket: + return "socket"; + } + assert(0 && "should not get here"); + return nullptr; +} + +int main(int ac, char** av) { + class lister { + file _f; + subscription<directory_entry> _listing; + public: + lister(file f) + : _f(std::move(f)) + , _listing(_f.list_directory([this] (directory_entry de) { return report(de); })) { + } + future<> done() { return _listing.done(); } + private: + future<> report(directory_entry de) { + return file_stat(de.name, follow_symlink::no).then([de = std::move(de)] (stat_data sd) { + if (de.type) { + assert(*de.type == sd.type); + } else { + assert(sd.type == directory_entry_type::unknown); + } + fmt::print("{} (type={})\n", de.name, de_type_desc(sd.type)); + return make_ready_future<>(); + }); + } + }; + return app_template().run(ac, av, [] { + return engine().open_directory(".").then([] (file f) { + return do_with(lister(std::move(f)), [] (lister& l) { + return l.done().then([] { + return 0; + }); + }); + }); + }); +} |