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"
18 std::optional
<sys::fs::file_status
> getFileStatus(StringRef Path
) {
19 sys::fs::file_status Status
;
20 std::error_code EC
= status(Path
, Status
);
26 std::vector
<std::string
> scanDirectory(StringRef Path
) {
27 using namespace llvm::sys
;
28 std::vector
<std::string
> Result
;
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());
37 Result
.emplace_back(sys::path::filename(It
->path()));
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
});