diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2019-10-23 17:52:09 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2019-10-23 17:52:09 +0000 |
commit | 519fc96c475680de2cc49e7811dbbfadb912cbcc (patch) | |
tree | 310ca684459b7e9ae13c9a3b9abf308b3a634afe /lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp | |
parent | 2298981669bf3bd63335a4be179bc0f96823a8f4 (diff) | |
download | src-vendor/clang.tar.gz src-vendor/clang.zip |
Vendor import of stripped clang trunk r375505, the last commit beforevendor/clang/clang-trunk-r375505vendor/clang
the upstream Subversion repository was made read-only, and the LLVM
project migrated to GitHub:
https://llvm.org/svn/llvm-project/cfe/trunk@375505
Notes
Notes:
svn path=/vendor/clang/dist/; revision=353942
svn path=/vendor/clang/clang-r375505/; revision=353943; tag=vendor/clang/clang-trunk-r375505
Diffstat (limited to 'lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp')
-rw-r--r-- | lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp b/lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp index 3df79ac48a4a..7a60369a4da0 100644 --- a/lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp +++ b/lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp @@ -11,20 +11,35 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Support/Error.h" #include "llvm/Support/Path.h" #include <CoreServices/CoreServices.h> using namespace llvm; using namespace clang; -static FSEventStreamRef createFSEventStream( - StringRef Path, - std::function<void(llvm::ArrayRef<DirectoryWatcher::Event>, bool)>, - dispatch_queue_t); static void stopFSEventStream(FSEventStreamRef); namespace { +/// This implementation is based on FSEvents API which implementation is +/// aggressively coallescing events. This can manifest as duplicate events. +/// +/// For example this scenario has been observed: +/// +/// create foo/bar +/// sleep 5 s +/// create DirectoryWatcherMac for dir foo +/// receive notification: bar EventKind::Modified +/// sleep 5 s +/// modify foo/bar +/// receive notification: bar EventKind::Modified +/// receive notification: bar EventKind::Modified +/// sleep 5 s +/// delete foo/bar +/// receive notification: bar EventKind::Modified +/// receive notification: bar EventKind::Modified +/// receive notification: bar EventKind::Removed class DirectoryWatcherMac : public clang::DirectoryWatcher { public: DirectoryWatcherMac( @@ -187,7 +202,7 @@ void stopFSEventStream(FSEventStreamRef EventStream) { FSEventStreamRelease(EventStream); } -std::unique_ptr<DirectoryWatcher> clang::DirectoryWatcher::create( +llvm::Expected<std::unique_ptr<DirectoryWatcher>> clang::DirectoryWatcher::create( StringRef Path, std::function<void(llvm::ArrayRef<DirectoryWatcher::Event>, bool)> Receiver, bool WaitForInitialSync) { @@ -195,15 +210,14 @@ std::unique_ptr<DirectoryWatcher> clang::DirectoryWatcher::create( dispatch_queue_create("DirectoryWatcher", DISPATCH_QUEUE_SERIAL); if (Path.empty()) - return nullptr; + llvm::report_fatal_error( + "DirectoryWatcher::create can not accept an empty Path."); auto EventStream = createFSEventStream(Path, Receiver, Queue); - if (!EventStream) { - return nullptr; - } + assert(EventStream && "EventStream expected to be non-null"); std::unique_ptr<DirectoryWatcher> Result = - llvm::make_unique<DirectoryWatcherMac>(EventStream, Receiver, Path); + std::make_unique<DirectoryWatcherMac>(EventStream, Receiver, Path); // We need to copy the data so the lifetime is ok after a const copy is made // for the block. |