1 //===- DirectoryScanner.cpp - Utility functions for DirectoryWatcher ------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "DirectoryScanner.h"
11 #include "llvm/Support/Path.h"
17 Optional
<sys::fs::file_status
> getFileStatus(StringRef Path
) {
18 sys::fs::file_status Status
;
19 std::error_code EC
= status(Path
, Status
);
25 std::vector
<std::string
> scanDirectory(StringRef Path
) {
26 using namespace llvm::sys
;
27 std::vector
<std::string
> Result
;
30 for (auto It
= fs::directory_iterator(Path
, EC
),
31 End
= fs::directory_iterator();
32 !EC
&& It
!= End
; It
.increment(EC
)) {
33 auto status
= getFileStatus(It
->path());
34 if (!status
.hasValue())
36 Result
.emplace_back(sys::path::filename(It
->path()));
42 std::vector
<DirectoryWatcher::Event
>
43 getAsFileEvents(const std::vector
<std::string
> &Scan
) {
44 std::vector
<DirectoryWatcher::Event
> Events
;
45 Events
.reserve(Scan
.size());
47 for (const auto &File
: Scan
) {
48 Events
.emplace_back(DirectoryWatcher::Event
{
49 DirectoryWatcher::Event::EventKind::Modified
, File
});