Skip to content

Commit bdcd781

Browse files
committed
Add recursive directory handling to inotify watcher
1 parent 73d84a2 commit bdcd781

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/Symfony/Component/Filesystem/Watcher/INotifyWatcher.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,16 @@ public function watch($path, callable $callback, float $timeout = null)
3131
stream_set_blocking($inotifyInit, false);
3232

3333
$isDir = is_dir($path);
34+
$watchers = [];
3435

3536
if ($isDir) {
36-
$watchId = inotify_add_watch($inotifyInit, $path, IN_CREATE | IN_DELETE | IN_MODIFY);
37+
$watchers[] = inotify_add_watch($inotifyInit, $path, IN_CREATE | IN_DELETE | IN_MODIFY);
38+
39+
foreach ($this->scanPath("$path/*") as $path) {
40+
$watchers[] = inotify_add_watch($inotifyInit, $path, IN_CREATE | IN_DELETE | IN_MODIFY);
41+
}
3742
} else {
38-
$watchId = inotify_add_watch($inotifyInit, $path, IN_MODIFY);
43+
$watchers[] = inotify_add_watch($inotifyInit, $path, IN_MODIFY);
3944
}
4045

4146
try {
@@ -77,8 +82,19 @@ public function watch($path, callable $callback, float $timeout = null)
7782
}
7883
}
7984
} finally {
80-
inotify_rm_watch($inotifyInit, $watchId);
85+
foreach ($watchers as $watchId) {
86+
inotify_rm_watch($inotifyInit, $watchId);
87+
}
88+
8189
fclose($inotifyInit);
8290
}
8391
}
92+
93+
private function scanPath($path)
94+
{
95+
foreach (glob($path, GLOB_ONLYDIR) as $directory) {
96+
yield $directory;
97+
yield from $this->scanPath("$directory/*");
98+
}
99+
}
84100
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy