Remove FileChange.isDirectory.
isDir can be a huge performance issue when watching a network based directory and can effectively block the thread almost completely in case of frequent file changes. This does mean than high-level code now needs to perform the check manually, if required, and the free information provided by inotify goes unused.
This commit is contained in:
parent
d7657b54e8
commit
86ee5c9477
5 changed files with 37 additions and 28 deletions
|
@ -1093,13 +1093,6 @@ struct FileChange {
|
|||
|
||||
/// Name of the changed file
|
||||
const(char)[] name;
|
||||
|
||||
/** Determines if the changed entity is a file or a directory.
|
||||
|
||||
Note that depending on the platform this may not be accurate for
|
||||
`FileChangeKind.removed`.
|
||||
*/
|
||||
bool isDirectory;
|
||||
}
|
||||
|
||||
/** Describes a spawned process
|
||||
|
|
|
@ -150,7 +150,6 @@ final class InotifyEventDriverWatchers(Events : EventDriverEvents) : EventDriver
|
|||
|
||||
ch.baseDirectory = m_watches[id].basePath;
|
||||
ch.directory = subdir;
|
||||
ch.isDirectory = (ev.mask & IN_ISDIR) != 0;
|
||||
ch.name = name;
|
||||
addRef(id); // assure that the id doesn't get invalidated until after the callback
|
||||
auto cb = m_loop.m_fds[id].watcher.callback;
|
||||
|
@ -487,9 +486,9 @@ final class PollEventDriverWatchers(Events : EventDriverEvents) : EventDriverWat
|
|||
|
||||
@property size_t entryCount() const { return m_entryCount; }
|
||||
|
||||
private void addChange(FileChangeKind kind, Key key, bool is_dir)
|
||||
private void addChange(FileChangeKind kind, Key key)
|
||||
{
|
||||
m_onChange(FileChange(kind, m_basePath, key.parent ? key.parent.path : "", key.name, is_dir));
|
||||
m_onChange(FileChange(kind, m_basePath, key.parent ? key.parent.path : "", key.name));
|
||||
}
|
||||
|
||||
private void scan(bool generate_changes)
|
||||
|
@ -506,12 +505,12 @@ final class PollEventDriverWatchers(Events : EventDriverEvents) : EventDriverWat
|
|||
foreach (e; m_entries.byKeyValue) {
|
||||
if (!e.key.parent || Key(e.key.parent.parent, e.key.parent.name) !in m_entries) {
|
||||
if (generate_changes)
|
||||
addChange(FileChangeKind.removed, e.key, e.value.isDir);
|
||||
addChange(FileChangeKind.removed, e.key);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (e; added)
|
||||
addChange(FileChangeKind.added, Key(e.parent, e.name), e.isDir);
|
||||
addChange(FileChangeKind.added, Key(e.parent, e.name));
|
||||
|
||||
swap(m_entries, new_entries);
|
||||
m_entryCount = ec;
|
||||
|
@ -539,7 +538,7 @@ final class PollEventDriverWatchers(Events : EventDriverEvents) : EventDriverWat
|
|||
} else {
|
||||
if ((*pe).size != de.size || (*pe).lastChange != modified_time) {
|
||||
if (generate_changes)
|
||||
addChange(FileChangeKind.modified, key, (*pe).isDir);
|
||||
addChange(FileChangeKind.modified, key);
|
||||
(*pe).size = de.size;
|
||||
(*pe).lastChange = modified_time;
|
||||
}
|
||||
|
|
|
@ -193,10 +193,7 @@ final class WinAPIEventDriverWatchers : EventDriverWatchers {
|
|||
ch.directory = dirName(path);
|
||||
if (ch.directory == ".") ch.directory = "";
|
||||
ch.name = baseName(path);
|
||||
try ch.isDirectory = isDir(fullpath);
|
||||
catch (Exception e) {} // FIXME: can happen if the base path is relative and the CWD has changed
|
||||
if (ch.kind != FileChangeKind.modified || !ch.isDirectory)
|
||||
slot.callback(id, ch);
|
||||
slot.callback(id, ch);
|
||||
if (fni.NextEntryOffset == 0 || !slot.callback) break;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue