Path: blob/main/contrib/llvm-project/clang/lib/DirectoryWatcher/DirectoryScanner.cpp
35260 views
//===- DirectoryScanner.cpp - Utility functions for DirectoryWatcher ------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "DirectoryScanner.h"910#include "llvm/Support/Path.h"11#include <optional>1213namespace clang {1415using namespace llvm;1617std::optional<sys::fs::file_status> getFileStatus(StringRef Path) {18sys::fs::file_status Status;19std::error_code EC = status(Path, Status);20if (EC)21return std::nullopt;22return Status;23}2425std::vector<std::string> scanDirectory(StringRef Path) {26using namespace llvm::sys;27std::vector<std::string> Result;2829std::error_code EC;30for (auto It = fs::directory_iterator(Path, EC),31End = fs::directory_iterator();32!EC && It != End; It.increment(EC)) {33auto status = getFileStatus(It->path());34if (!status)35continue;36Result.emplace_back(sys::path::filename(It->path()));37}3839return Result;40}4142std::vector<DirectoryWatcher::Event>43getAsFileEvents(const std::vector<std::string> &Scan) {44std::vector<DirectoryWatcher::Event> Events;45Events.reserve(Scan.size());4647for (const auto &File : Scan) {48Events.emplace_back(DirectoryWatcher::Event{49DirectoryWatcher::Event::EventKind::Modified, File});50}51return Events;52}5354} // namespace clang555657