/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/DirectoryWatcher/DirectoryScanner.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===- DirectoryScanner.cpp - Utility functions for DirectoryWatcher ------===// |
2 | | // |
3 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | | // See https://llvm.org/LICENSE.txt for license information. |
5 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | |
9 | | #include "DirectoryScanner.h" |
10 | | |
11 | | #include "llvm/Support/Path.h" |
12 | | #include <optional> |
13 | | |
14 | | namespace clang { |
15 | | |
16 | | using namespace llvm; |
17 | | |
18 | 13 | std::optional<sys::fs::file_status> getFileStatus(StringRef Path) { |
19 | 13 | sys::fs::file_status Status; |
20 | 13 | std::error_code EC = status(Path, Status); |
21 | 13 | if (EC) |
22 | 0 | return std::nullopt; |
23 | 13 | return Status; |
24 | 13 | } |
25 | | |
26 | 8 | std::vector<std::string> scanDirectory(StringRef Path) { |
27 | 8 | using namespace llvm::sys; |
28 | 8 | std::vector<std::string> Result; |
29 | | |
30 | 8 | std::error_code EC; |
31 | 8 | for (auto It = fs::directory_iterator(Path, EC), |
32 | 8 | End = fs::directory_iterator(); |
33 | 17 | !EC && It != End; It.increment(EC)9 ) { |
34 | 9 | auto status = getFileStatus(It->path()); |
35 | 9 | if (!status) |
36 | 0 | continue; |
37 | 9 | Result.emplace_back(sys::path::filename(It->path())); |
38 | 9 | } |
39 | | |
40 | 8 | return Result; |
41 | 8 | } |
42 | | |
43 | | std::vector<DirectoryWatcher::Event> |
44 | 8 | getAsFileEvents(const std::vector<std::string> &Scan) { |
45 | 8 | std::vector<DirectoryWatcher::Event> Events; |
46 | 8 | Events.reserve(Scan.size()); |
47 | | |
48 | 9 | for (const auto &File : Scan) { |
49 | 9 | Events.emplace_back(DirectoryWatcher::Event{ |
50 | 9 | DirectoryWatcher::Event::EventKind::Modified, File}); |
51 | 9 | } |
52 | 8 | return Events; |
53 | 8 | } |
54 | | |
55 | | } // namespace clang |