[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / lib / DirectoryWatcher / DirectoryScanner.cpp
blob428f87eddc7b60e06a91e6175e4859a523d2a82a
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 //===----------------------------------------------------------------------===//
9 #include "DirectoryScanner.h"
11 #include "llvm/Support/Path.h"
12 #include <optional>
14 namespace clang {
16 using namespace llvm;
18 std::optional<sys::fs::file_status> getFileStatus(StringRef Path) {
19 sys::fs::file_status Status;
20 std::error_code EC = status(Path, Status);
21 if (EC)
22 return std::nullopt;
23 return Status;
26 std::vector<std::string> scanDirectory(StringRef Path) {
27 using namespace llvm::sys;
28 std::vector<std::string> Result;
30 std::error_code EC;
31 for (auto It = fs::directory_iterator(Path, EC),
32 End = fs::directory_iterator();
33 !EC && It != End; It.increment(EC)) {
34 auto status = getFileStatus(It->path());
35 if (!status)
36 continue;
37 Result.emplace_back(sys::path::filename(It->path()));
40 return Result;
43 std::vector<DirectoryWatcher::Event>
44 getAsFileEvents(const std::vector<std::string> &Scan) {
45 std::vector<DirectoryWatcher::Event> Events;
46 Events.reserve(Scan.size());
48 for (const auto &File : Scan) {
49 Events.emplace_back(DirectoryWatcher::Event{
50 DirectoryWatcher::Event::EventKind::Modified, File});
52 return Events;
55 } // namespace clang