diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/RefreshWorker.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/RefreshWorker.java index 42495b57f2c0..5cb9149e4997 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/RefreshWorker.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/RefreshWorker.java @@ -228,7 +228,9 @@ public class RefreshWorker { } } - file.markClean(); + if (myIsRecursive || !file.isDirectory()) { + file.markClean(); + } } } diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/FileWatcherTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/FileWatcherTest.java index 4dc17f00dfad..19d9beb1959e 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/FileWatcherTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/FileWatcherTest.java @@ -674,6 +674,12 @@ public class FileWatcherTest extends PlatformLangTestCase { } } + public void testPartialRefresh() throws Exception { + // tests the same scenario with an active file watcher: this affects + File top = createTestDir("top"); + LocalFileSystemTest.doTestPartialRefresh(top); + } + @NotNull private LocalFileSystem.WatchRequest watch(File watchFile) { diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/LocalFileSystemTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/LocalFileSystemTest.java index 7ee40baacf3f..ca6b5ae32ff3 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/LocalFileSystemTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/LocalFileSystemTest.java @@ -437,4 +437,40 @@ public class LocalFileSystemTest extends PlatformLangTestCase { assertTrue(sourceFile.isValid()); assertEquals(newName, sourceFile.getName()); } + + public void testPartialRefresh() throws Exception { + File top = createTempDirectory(false); + doTestPartialRefresh(top); + } + + public static void doTestPartialRefresh(File top) throws IOException { + File sub = IoTestUtil.createTestDir(top, "sub"); + File file = IoTestUtil.createTestFile(top, "sub.txt"); + LocalFileSystem lfs = LocalFileSystem.getInstance(); + NewVirtualFile topDir = (NewVirtualFile)lfs.refreshAndFindFileByIoFile(top); + assertNotNull(topDir); + NewVirtualFile subDir = (NewVirtualFile)lfs.refreshAndFindFileByIoFile(sub); + assertNotNull(subDir); + NewVirtualFile subFile = (NewVirtualFile)lfs.refreshAndFindFileByIoFile(file); + assertNotNull(subFile); + topDir.refresh(false, true); + assertFalse(topDir.isDirty()); + assertFalse(subDir.isDirty()); + assertFalse(subFile.isDirty()); + + subFile.markDirty(); + subDir.markDirty(); + assertTrue(topDir.isDirty()); + assertTrue(subFile.isDirty()); + assertTrue(subDir.isDirty()); + + topDir.refresh(false, false); + assertFalse(subFile.isDirty()); + assertTrue(subDir.isDirty()); // should stay unvisited after non-recursive refresh + + topDir.refresh(false, true); + assertFalse(topDir.isDirty()); + assertFalse(subFile.isDirty()); + assertFalse(subDir.isDirty()); + } }