Merge pull request #34 from vibe-d/avoid_dot_in_watcher_path

Avoid "." path in InotifyEventDriverWatchers.
merged-on-behalf-of: Sönke Ludwig <s-ludwig@users.noreply.github.com>
This commit is contained in:
The Dlang Bot 2017-11-22 18:28:27 +01:00 committed by GitHub
commit 1cadc3077b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 6 deletions

View file

@ -41,7 +41,7 @@ final class InotifyEventDriverWatchers(Events : EventDriverEvents) : EventDriver
m_watches[ret] = WatchState(null, path, recursive);
addWatch(ret, path, ".");
addWatch(ret, path, "");
if (recursive) {
try {
auto base_segements = path.pathSplitter.walkLength;
@ -138,7 +138,7 @@ final class InotifyEventDriverWatchers(Events : EventDriverEvents) : EventDriver
auto subdir = w.watcherPaths[ev.wd];
if (w.recursive && ev.mask & (IN_CREATE|IN_MOVED_TO) && ev.mask & IN_ISDIR) {
addWatch(id, w.basePath, subdir == "." ? name.idup : buildPath(subdir, name));
addWatch(id, w.basePath, subdir == "" ? name.idup : buildPath(subdir, name));
}
ch.baseDirectory = m_watches[id].basePath;

View file

@ -123,6 +123,7 @@ final class WinAPIEventDriverWatchers : EventDriverWatchers {
auto path = () @trusted { scope (failure) assert(false); return to!string(fni.FileName[0 .. fni.FileNameLength/2]); } ();
auto fullpath = buildPath(slot.directory, path);
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

View file

@ -160,5 +160,7 @@ print("test %s RENAME %s %s", from, to, expect_change);
FileChange fchange(FileChangeKind kind, string name, bool is_dir)
{
return FileChange(kind, testDir, dirName(name), baseName(name), is_dir);
auto dn = dirName(name);
if (dn == ".") dn = "";
return FileChange(kind, testDir, dn, baseName(name), is_dir);
}

View file

@ -27,17 +27,20 @@ void main()
default: assert(false);
case 0:
assert(change.kind == FileChangeKind.added);
assert(change.directory == ".");
assert(change.baseDirectory == ".");
assert(change.directory == "");
assert(change.name == testFilename);
break;
case 1:
assert(change.kind == FileChangeKind.modified);
assert(change.directory == ".");
assert(change.baseDirectory == ".");
assert(change.directory == "");
assert(change.name == testFilename);
break;
case 2:
assert(change.kind == FileChangeKind.removed);
assert(change.directory == ".");
assert(change.baseDirectory == ".");
assert(change.directory == "");
assert(change.name == testFilename);
eventDriver.watchers.releaseRef(id);
s_done = true;