platform: recursively invalidate VFS subtree on directory deletion/creation

Fixes the issue of missed changes when a subtree is moved out and a similar one is moved on it's place.
This commit is contained in:
Roman Shevchenko
2015-05-08 19:21:22 +02:00
parent 9155a2b975
commit 0f9583bcba
2 changed files with 29 additions and 2 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -556,7 +556,7 @@ public class FileWatcher {
case CREATE:
case DELETE:
for (String p : paths) {
myDirtyPaths.dirtyPaths.add(p);
myDirtyPaths.dirtyPathsRecursive.add(p);
String parentPath = new File(p).getParent();
if (parentPath != null) {
myDirtyPaths.dirtyPaths.add(parentPath);
@@ -714,6 +714,33 @@ public class FileWatcherTest extends PlatformLangTestCase {
}
}
public void testDisplacementByIsomorphicTree() throws Exception {
File top = createTestDir("top");
File up = createTestDir(top, "up");
File middle = createTestDir(up, "middle");
File file = createTestFile(middle, "file.txt", "original content");
File up_copy = new File(top, "up_copy");
FileUtil.copyDir(up, up_copy);
FileUtil.writeToFile(file, "new content");
VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
assertNotNull(vFile);
assertEquals("new content", VfsUtilCore.loadText(vFile));
LocalFileSystem.WatchRequest request = watch(up);
try {
myAccept = true;
FileUtil.rename(up, new File(top, "up.bak"));
FileUtil.rename(up_copy, up);
assertEvent(VFileContentChangeEvent.class, file.getPath());
assertTrue(vFile.isValid());
assertEquals("original content", VfsUtilCore.loadText(vFile));
}
finally {
unwatch(request);
}
}
@NotNull
private LocalFileSystem.WatchRequest watch(File watchFile) {