clang  14.0.0git
DirectoryScanner.cpp
Go to the documentation of this file.
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 
13 namespace clang {
14 
15 using namespace llvm;
16 
18  sys::fs::file_status Status;
19  std::error_code EC = status(Path, Status);
20  if (EC)
21  return None;
22  return Status;
23 }
24 
25 std::vector<std::string> scanDirectory(StringRef Path) {
26  using namespace llvm::sys;
27  std::vector<std::string> Result;
28 
29  std::error_code EC;
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())
35  continue;
36  Result.emplace_back(sys::path::filename(It->path()));
37  }
38 
39  return Result;
40 }
41 
42 std::vector<DirectoryWatcher::Event>
43 getAsFileEvents(const std::vector<std::string> &Scan) {
44  std::vector<DirectoryWatcher::Event> Events;
45  Events.reserve(Scan.size());
46 
47  for (const auto &File : Scan) {
48  Events.emplace_back(DirectoryWatcher::Event{
50  }
51  return Events;
52 }
53 
54 } // namespace clang
llvm
Definition: Dominators.h:30
clang::DeclaratorContext::File
@ File
llvm::Optional
Definition: LLVM.h:40
clang::getFileStatus
Optional< sys::fs::file_status > getFileStatus(StringRef Path)
Definition: DirectoryScanner.cpp:17
End
SourceLocation End
Definition: USRLocFinder.cpp:167
clang::DirectoryWatcher::Event::EventKind::Modified
@ Modified
Content of a file was modified.
DirectoryScanner.h
clang::DirectoryWatcher::Event
Definition: DirectoryWatcher.h:66
clang::getAsFileEvents
std::vector< DirectoryWatcher::Event > getAsFileEvents(const std::vector< std::string > &Scan)
Create event with EventKind::Added for every element in Scan.
Definition: DirectoryScanner.cpp:43
clang
Definition: CalledOnceCheck.h:17
Scan
static void Scan(IvarUsageMap &M, const Stmt *S)
Definition: ObjCUnusedIVarsChecker.cpp:32
clang::scanDirectory
std::vector< std::string > scanDirectory(StringRef Path)
Definition: DirectoryScanner.cpp:25