Skip to content

Commit

Permalink
Fix DirectoryWatcher bugs on macOS and iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
etcimon committed Dec 14, 2023
1 parent a81bb13 commit 77292e9
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions source/libasync/posix.d
Original file line number Diff line number Diff line change
Expand Up @@ -537,10 +537,6 @@ package:
}


}
else /* if KQUEUE */
{
assert(false, "Unsupported platform for async DNS");
}
break;

Expand Down Expand Up @@ -2115,12 +2111,20 @@ private:
//writeln("m_dwFiles length: ", m_dwFiles.length);

// get a list of the folder
foreach (de; dirEntries(path.toNativeString(), SpanMode.shallow)) {
foreach (DirEntry de; dirEntries(path.toNativeString(), SpanMode.shallow)) {
//writeln(de.name);
Path entryPath = Path(de.name);
bool found;

if (!de.isDir()) {
if (fi.wi.recursive && de.isDir()) {
foreach (ref DWFolderInfo folder; m_dwFolders) {
if (folder.wi.path == entryPath) {
found = true;
break;
}
}
}
else {
// compare it to the cached list fixme: make it faster using another container?
foreach (ref const fd_t id, ref const DWFileInfo file; m_dwFiles) {
if (file.folder != wd) continue; // this file isn't in the evented folder
Expand All @@ -2138,14 +2142,7 @@ private:
break;
}
}
} else {
foreach (ref DWFolderInfo folder; m_dwFolders) {
if (folder.wi.path == entryPath) {
found = true;
break;
}
}
}
}

// This file/folder is new in the folder
if (!found) {
Expand All @@ -2157,7 +2154,7 @@ private:
/// Useful e.g. when mkdir -p is used.
watch(fd, WatchInfo(fi.wi.events, entryPath, fi.wi.recursive, wd) );
void genEvents(Path subpath) {
foreach (de; dirEntries(subpath.toNativeString(), SpanMode.shallow)) {
foreach (DirEntry de; dirEntries(subpath.toNativeString(), SpanMode.shallow)) {
auto subsubpath = Path(de.name);
if (!subsubpath.absolute())
subsubpath = subpath ~ subsubpath;
Expand Down

0 comments on commit 77292e9

Please sign in to comment.