VFS does not pick up changes made outside of VFS when doing asynchRefresh

I'm using a  `com.intellij.openapi.startup.StartupActivity` to run the following background task:



 ProgressManager.getInstance().run(new Task.Backgroundable(project, "Updating Skeletons", false) {
public void run(@NotNull ProgressIndicator indicator) {
File createdFileOutsideVFS = new File(RSkeletonGenerator.getSkeletonsPath(), "ggExtra.R");

// ... some logic to create this file ...

// once done wait for VFS and stub-index to pick up the changes and do some follow up task using the stub-index
VirtualFileManager.getInstance().asyncRefresh(() -> {

// double check that the file actually there
System.err.println("ggextra file exists:" + createdFileOutsideVFS.exists());
// returns true as expected

System.err.println("ggextra vfs instance:" + VfsUtil.findFileByIoFile(createdFileOutsideVFS, false));
// gives null!!

// run logic that now assumes that the new file is part of VFS and stub-indexed


1. a new File is created in one of the project libaries but outside of VFS

2. A asnc refresh with a postAction is triggered.

3. WIthin the postAction I would extect that the VFS is now aware of the file but it isntt. I can verify it's presence via the java.io.File API but when trying to locate it via VfsUtil.findFileByIOFile it is null. Also the stub-manager has not picked up and indexed the newly added library file.

Do you have an idea about what is wrong with code and how to fix it? I've noticed that I run `VfsUtil.findFileByIOFile()` with `refreshNeeded=true` it return the correct non-null vfsfile instance. However, I thought that by running  the `asyncRefresh` it would refresh all files internally already.

Thanks in advance.



1 comment

For a file to be picked up by the VFS, it should be created under a watch root (see com.intellij.openapi.vfs.LocalFileSystem#addRootsToWatch), and then reported by a helper "fsnotifier" process (with takes some time). In your case, it would be easier to update the VFS synchronously, via com.intellij.openapi.vfs.LocalFileSystem#refreshAndFindFileByIoFile.

Sorry for the late reply.


Please sign in to leave a comment.