Repository: hannah-sten/texify-idea
Issue: Failed to delete all output files

#### Type of JetBrains IDE (IntelliJ, PyCharm, etc.) and version
IntelliJ IDEA 2022.2.1 (Ultimate Edition) Build #IU-222.3739.54
#### Operating System 
macOS 12.5.1 M1
#### TeXiFy IDEA version
0.7.22-alpha.1
#### What I did (steps to reproduce)
Trying to delete all output files over Tools → LaTeX → Delete All Output Files
#### The full stacktrace of the exception thrown
```
com.intellij.openapi.vfs.InvalidVirtualFileAccessException: Accessing invalid virtual file: file:///Users/svsi/Repos/bachelor_thesis/out; original:741898; found:742026; File.exists()=true
	at com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl.handleInvalidDirectory(VirtualDirectoryImpl.java:191)
	at com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl.getChildren(VirtualDirectoryImpl.java:397)
	at nl.hannahsten.texifyidea.action.DeleteGeneratedFiles$deleteFiles$5.invoke(DeleteGeneratedFiles.kt:77)
	at nl.hannahsten.texifyidea.action.DeleteGeneratedFiles$deleteFiles$5.invoke(DeleteGeneratedFiles.kt:75)
	at nl.hannahsten.texifyidea.util.GeneralKt.runWriteAction$lambda-0(General.kt:48)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:1023)
	at nl.hannahsten.texifyidea.util.GeneralKt.runWriteAction(General.kt:48)
	at nl.hannahsten.texifyidea.action.DeleteGeneratedFiles.deleteFiles(DeleteGeneratedFiles.kt:75)
	at nl.hannahsten.texifyidea.action.DeleteGeneratedFiles.actionPerformed(DeleteGeneratedFiles.kt:25)
	at com.intellij.openapi.actionSystem.ex.ActionUtil.doPerformActionOrShowPopup(ActionUtil.java:315)
	at com.intellij.openapi.actionSystem.ex.ActionUtil.lambda$performActionDumbAwareWithCallbacks$4(ActionUtil.java:294)
	at com.intellij.openapi.actionSystem.ex.ActionUtil.performDumbAwareWithCallbacks(ActionUtil.java:337)
	at com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAwareWithCallbacks(ActionUtil.java:294)
	at com.intellij.openapi.actionSystem.impl.ActionMenuItem.lambda$performAction$4(ActionMenuItem.java:293)
	at com.intellij.openapi.wm.impl.FocusManagerImpl.runOnOwnContext(FocusManagerImpl.java:227)
	at com.intellij.openapi.actionSystem.impl.ActionMenuItem.performAction(ActionMenuItem.java:286)
	at com.intellij.openapi.actionSystem.impl.ActionMenuItem.lambda$new$1(ActionMenuItem.java:78)
	at com.intellij.openapi.application.TransactionGuardImpl.runWithWritingAllowed(TransactionGuardImpl.java:209)
	at com.intellij.openapi.application.TransactionGuardImpl.access$100(TransactionGuardImpl.java:21)
	at com.intellij.openapi.application.TransactionGuardImpl$1.run(TransactionGuardImpl.java:191)
	at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:881)
	at com.intellij.openapi.application.impl.ApplicationImpl$3.run(ApplicationImpl.java:513)
	at com.intellij.openapi.application.impl.FlushQueue.doRun(FlushQueue.java:75)
	at com.intellij.openapi.application.impl.FlushQueue.runNextEvent(FlushQueue.java:118)
	at com.intellij.openapi.application.impl.FlushQueue.flushNow(FlushQueue.java:42)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:779)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:730)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:724)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:749)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:918)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:766)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$6(IdeEventQueue.java:450)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:791)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$7(IdeEventQueue.java:449)
	at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:105)
	at com.intellij.ide.IdeEventQueue.performActivity(IdeEventQueue.java:624)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:447)
	at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:881)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:493)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92)
```



Changed files:
src/nl/hannahsten/texifyidea/action/DeleteGeneratedFiles.kt

diff --git a/src/nl/hannahsten/texifyidea/action/DeleteGeneratedFiles.kt b/src/nl/hannahsten/texifyidea/action/DeleteGeneratedFiles.kt
index 7ae373174..4be5b0b01 100644
--- a/src/nl/hannahsten/texifyidea/action/DeleteGeneratedFiles.kt
+++ b/src/nl/hannahsten/texifyidea/action/DeleteGeneratedFiles.kt
@@ -6,8 +6,9 @@ import com.intellij.openapi.actionSystem.AnAction
 import com.intellij.openapi.actionSystem.AnActionEvent
 import com.intellij.openapi.ui.Messages
 import com.intellij.openapi.ui.showOkCancelDialog
+import com.intellij.openapi.vfs.InvalidVirtualFileAccessException
 import com.intellij.openapi.vfs.LocalFileSystem
-import com.intellij.openapi.vfs.VirtualFile
+import nl.hannahsten.texifyidea.util.Log
 import nl.hannahsten.texifyidea.util.getLatexRunConfigurations
 import nl.hannahsten.texifyidea.util.magic.FileMagic
 import nl.hannahsten.texifyidea.util.runWriteAction
@@ -38,13 +39,14 @@ class DeleteGeneratedFiles : AnAction() {
             .flatMap { listOf(it.outputPath.getAndCreatePath(), it.auxilPath.getAndCreatePath()) }
             // There's no reason to delete files outside the project
             .filter { it?.path?.contains(project.basePath!!) == true }
+            .filterNotNull()
 
         val result = showOkCancelDialog(
             "Delete Auxiliary and Output Files",
             "Do you really want to delete all files in LaTeX output directories, " +
                 "and all auxiliary and generated files? \\n" +
                 "All files in the following output directories will be deleted: \\n" +
-                customOutput.mapNotNull { it?.path }.joinToString { "  $it\\n" } +
+                customOutput.map { it.path }.joinToString { "  $it\\n" } +
                 "plus auxiliary and generated files in src/, auxil/ and out/.\\n" +
                 "Be careful when doing this, you might not be able to fully undo this operation!",
             "Delete"
@@ -69,24 +71,31 @@ class DeleteGeneratedFiles : AnAction() {
             path.walk().maxDepth(1).forEach { it.delete() }
         }
 
-        val notDeleted = mutableListOf<VirtualFile>()
+        val notDeleted = mutableListOf<String>()
 
         // Custom out/aux dirs
         runWriteAction {
             for (path in customOutput) {
-                path?.children?.forEach {
-                    try {
-                        it.delete(this)
-                    }
-                    catch (e: IOException) {
-                        notDeleted.add(it)
+                try {
+                    path.children?.forEach {
+                        try {
+                            it.delete(this)
+                        }
+                        catch (e: IOException) {
+                            Log.warn(e.message ?: e.toString())
+                            notDeleted.add(it.path)
+                        }
                     }
                 }
+                catch (e: InvalidVirtualFileAccessException) {
+                    Log.warn(e.message ?: e.toString())
+                    notDeleted.add(path.path)
+                }
             }
         }
 
         if (notDeleted.isNotEmpty()) {
-            Notification("LaTeX", "Could not delete some files", "The following files need to be deleted manually: ${notDeleted.map { it.path }}", NotificationType.WARNING).notify(project)
+            Notification("LaTeX", "Could not delete some files", "The following files need to be deleted manually: $notDeleted", NotificationType.WARNING).notify(project)
         }
 
         // Generated minted files