exbin / bined-intellij-plugin

Hex viewer/editor plugin for JetBrains IntelliJ platform
https://bined.exbin.org/intellij-plugin
Apache License 2.0
59 stars 9 forks source link

opened files remain "locked" after closing the tab/window #34

Closed peppemas closed 9 months ago

peppemas commented 3 years ago

If you open a file with the plugin and then close the tab/window you can't delete the file. You should close the file when tab/window is closed.

hajdam commented 3 years ago

There might be an issue with DELTA file handling mode (files are locked with partial access). I had plan to rework it, but had long-term health issues myself.

As a workaround, it should help to set "File Handling Mode" in Options/Editor to MEMORY. (unless there is another issue I'm not aware of yet)

Komediruzecki commented 1 year ago

Hi,

this workaround does not seem to work, same behavior stays.

Is it possible to provide a patch for this or allow contributions?

hajdam commented 1 year ago

Hi, I sorry to hear that workaround is not working. If you know any fix feel free to submit patch or raise pull request.

Daskie commented 1 year ago

+1 This issue completely obstructs my primary use case of viewing frequently deleted cache files

Komediruzecki commented 1 year ago

Hi, I have forked and built plugin in IDEA,

Seems to me that there are 2 ways to open the BIN file in editor:

Via File -> Open BinEd -> Select file Double click and assign file type to BinEd

The first type of opening seems to call the close/dispose on file.

The second seems not to use that code and no event is triggered.

I also found that setClosed is used before attaching the close file action on virtual file, not sure if this is a bug.

Ill try to investigate this a bit more over the weekend and try to provide solution.

Seggan commented 1 year ago

Can confirm this is happening, with an "invalid virtual file" error

lppedd commented 1 year ago

This is the only issue that prevents me from using the plugin. Overall I can't ask more out of it, but this... makes it a PITA.

hajdam commented 1 year ago

Can anyone provide reproduction steps for this?

From my testing of current version (0.2.8.1) on Windows 10, file gets locked only when DELTA memory handling mode is used. When MEMORY handling mode is used or when file opened via set-up file type, file can be written to.

I tested this opening/editing file using plugin in IntelliJ while trying to write to it in command line, for example with command: notepad.exe>>testfile.dat or del testfile.dat

lppedd commented 1 year ago

@hajdam yup, MEMORY indeed solves the issue.
However, I can't seem to reliably reproduce with DELTA. Sometimes it locks the file, sometimes it doesn't.

Komediruzecki commented 1 year ago

Hi,

On version 0.2.8.1:

File gets deleted but exception is thrown:

  1. Open file in BinEd
  2. Don't change anything
  3. Close with clicking the 'X' on editor tab
  4. Delete file by clicking on it in file tree and press 'Delete'

For me it is 'Broken Virtual File' and then no such file (since it does get deleted?!) Exception: java.lang.RuntimeException: Cannot invoke (class=, method=after, topic=BulkFileListener) at com.intellij.util.messages.impl.MessageBusImplKt.invokeListener(MessageBusImpl.kt:676) at com.intellij.util.messages.impl.MessageBusImplKt.executeOrAddToQueue(MessageBusImpl.kt:491) at com.intellij.util.messages.impl.ToDirectChildrenMessagePublisher.publish$intellij_platform_core(CompositeMessageBus.kt:310) at com.intellij.util.messages.impl.MessagePublisher.invoke(MessageBusImpl.kt:448) at jdk.proxy2/jdk.proxy2.$Proxy95.after(Unknown Source) at com.intellij.openapi.vfs.newvfs.persistent.PersistentFSImpl.lambda$fireAfterEvents$19(PersistentFSImpl.java:1326) at com.intellij.openapi.vfs.newvfs.persistent.PersistentFSImpl.runSuppressing(PersistentFSImpl.java:955) at com.intellij.openapi.vfs.newvfs.persistent.PersistentFSImpl.fireAfterEvents(PersistentFSImpl.java:1323) at com.intellij.openapi.vfs.newvfs.persistent.PersistentFSImpl.lambda$processEvent$7(PersistentFSImpl.java:921) at com.intellij.openapi.vfs.newvfs.persistent.PersistentFSImpl.runSuppressing(PersistentFSImpl.java:955) at com.intellij.openapi.vfs.newvfs.persistent.PersistentFSImpl.processEvent(PersistentFSImpl.java:918) at com.intellij.openapi.vfs.newvfs.persistent.PersistentFSImpl.deleteFile(PersistentFSImpl.java:618) at com.intellij.openapi.vfs.newvfs.impl.VirtualFileSystemEntry.delete(VirtualFileSystemEntry.java:306) at com.intellij.psi.impl.file.PsiFileImplUtil.doDelete(PsiFileImplUtil.java:68) at com.intellij.psi.impl.file.PsiBinaryFileImpl.delete(PsiBinaryFileImpl.java:209) at com.intellij.ide.util.DeleteHandler.lambda$doDeleteFiles$5(DeleteHandler.java:333) at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:992) at com.intellij.ide.util.DeleteHandler.doDeleteFiles(DeleteHandler.java:330) at com.intellij.ide.util.DeleteHandler.lambda$deleteInCommand$0(DeleteHandler.java:223) at com.intellij.openapi.fileEditor.impl.NonProjectFileWritingAccessProvider.disableChecksDuring(NonProjectFileWritingAccessProvider.java:170) at com.intellij.ide.util.DeleteHandler.lambda$deleteInCommand$1(DeleteHandler.java:210) at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:219) at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:174) at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:164) at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:150) at com.intellij.ide.util.DeleteHandler.deleteInCommand(DeleteHandler.java:210) at com.intellij.ide.util.DeleteHandler.deletePsiElement(DeleteHandler.java:195) at com.intellij.ide.util.DeleteHandler.deletePsiElement(DeleteHandler.java:122) at com.intellij.ide.projectView.impl.ProjectViewDeleteElementProvider.deleteElement(ProjectViewDeleteElementProvider.java:58) at com.intellij.ide.actions.DeleteAction.actionPerformed(DeleteAction.java:33) at com.intellij.openapi.actionSystem.ex.ActionUtil.doPerformActionOrShowPopup(ActionUtil.java:339) at com.intellij.openapi.keymap.impl.ActionProcessor.performAction(ActionProcessor.java:47) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher$myActionProcessor$1.performAction(IdeKeyEventDispatcher.kt:502) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcherKt.doPerformActionInner$lambda$5$lambda$4(IdeKeyEventDispatcher.kt:865) at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:105) at com.intellij.openapi.application.TransactionGuardImpl.performUserActivity(TransactionGuardImpl.java:94) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcherKt.doPerformActionInner$lambda$5(IdeKeyEventDispatcher.kt:865) at com.intellij.openapi.actionSystem.ex.ActionUtil.performDumbAwareWithCallbacks(ActionUtil.java:362) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcherKt.doPerformActionInner(IdeKeyEventDispatcher.kt:863) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcherKt.access$doPerformActionInner(IdeKeyEventDispatcher.kt:1) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction$intellij_platform_ide_impl(IdeKeyEventDispatcher.kt:587) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction(IdeKeyEventDispatcher.kt:513) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processActionOrWaitSecondStroke(IdeKeyEventDispatcher.kt:454) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.inInitState(IdeKeyEventDispatcher.kt:447) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.dispatchKeyEvent(IdeKeyEventDispatcher.kt:309) at com.intellij.ide.IdeEventQueue.dispatchKeyEvent(IdeEventQueue.kt:617) at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.kt:587) at com.intellij.ide.IdeEventQueue.access$_dispatchEvent(IdeEventQueue.kt:67) at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.compute(IdeEventQueue.kt:369) at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.compute(IdeEventQueue.kt:368) at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:787) at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1.invoke(IdeEventQueue.kt:368) at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1.invoke(IdeEventQueue.kt:363) at com.intellij.ide.IdeEventQueueKt.performActivity$lambda$1(IdeEventQueue.kt:992) at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:113) at com.intellij.ide.IdeEventQueueKt.performActivity(IdeEventQueue.kt:992) at com.intellij.ide.IdeEventQueue.dispatchEvent$lambda$7(IdeEventQueue.kt:363) at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:861) at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.kt:405) 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) Caused by: java.lang.IllegalStateException: Broken virtual file:C:/Users/user.name/sw_projects/project/project/app_debug/app_bjb_debug.bin at org.exbin.bined.intellij.BinEdFileDataWrapper.createBrokenVirtualFileException(BinEdFileDataWrapper.java:563) at org.exbin.bined.intellij.BinEdFileDataWrapper.loadPage(BinEdFileDataWrapper.java:544) at org.exbin.bined.intellij.BinEdFileDataWrapper.copyTo(BinEdFileDataWrapper.java:151) at org.exbin.bined.intellij.BinEdFileDataWrapper.copyToArray(BinEdFileDataWrapper.java:137) at org.exbin.framework.bined.gui.ValuesPanel.updateValues(ValuesPanel.java:808) at org.exbin.framework.bined.gui.ValuesPanel.lambda$enableUpdate$0(ValuesPanel.java:747) at java.base/java.util.ArrayList.forEach(ArrayList.java:1511) at org.exbin.bined.swing.CodeAreaCore.notifyDataChanged(CodeAreaCore.java:189) at org.exbin.bined.swing.extended.ExtCodeArea.notifyDataChanged(ExtCodeArea.java:538) at org.exbin.bined.operation.swing.CodeAreaUndoHandler.undoUpdated(CodeAreaUndoHandler.java:272) at org.exbin.bined.operation.swing.CodeAreaUndoHandler.clear(CodeAreaUndoHandler.java:184) at org.exbin.bined.intellij.BinEdNativeFile$1.after(BinEdNativeFile.java:114) at com.intellij.util.messages.impl.MessageBusImplKt.invokeMethod(MessageBusImpl.kt:699) at com.intellij.util.messages.impl.MessageBusImplKt.invokeListener(MessageBusImpl.kt:663) ... 64 more Caused by: java.nio.file.NoSuchFileException: C:\Users\user.name\project\project\app_debug\app_bjb_debug.bin at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:85) at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103) at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108) at java.base/sun.nio.fs.WindowsFileSystemProvider.newByteChannel(WindowsFileSystemProvider.java:236) at java.base/java.nio.file.Files.newByteChannel(Files.java:380) at java.base/java.nio.file.Files.newByteChannel(Files.java:432) at java.base/java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:422) at java.base/java.nio.file.Files.newInputStream(Files.java:160) at com.intellij.openapi.vfs.impl.local.LocalFileSystemBase.getInputStream(LocalFileSystemBase.java:470) at com.intellij.openapi.vfs.newvfs.persistent.PersistentFSImpl.getInputStream(PersistentFSImpl.java:720) at com.intellij.openapi.vfs.newvfs.impl.VirtualFileImpl.getInputStream(VirtualFileImpl.java:108) at org.exbin.bined.intellij.BinEdFileDataWrapper.getCachedInputStream(BinEdFileDataWrapper.java:499) at org.exbin.bined.intellij.BinEdFileDataWrapper.loadPage(BinEdFileDataWrapper.java:523) ... 76 more

Also, undoing file delete restores the empty file with 0 bytes.

Changing to MEMORY handling does work now, I didn't see crash or unable to delete (but one needs to change the handling mode and then reopen the file), also the undo delete retrieves the correct file. Tested in Clion 2023.2 (Build #CL-232.8660.186, built on July 26, 2023)

The issue doesn't seem to happen multiple times on same file, it has to be new file just opened in BinEd, then when closing editor and deleting file, the exception occurs. Further open/close/delete attempts don't cause exceptions (sometimes even multiple attempts throw exception, maybe depends on how IDE handles detection and reporting of this). Closing IDE, opening IDE, opening BIN file in BinEd, closing editor tab and deleting file again causes exception on this first attempt.

Reproducing this might be related to how Clion and its settings handles file open/delete, for me the file does not go to Recycle Bin when deleted.

hajdam commented 1 year ago

I'm in the middle of internal refactoring, but if anyone is willing please test current development build, there should be some mitigations to locking issue: https://bined.exbin.org/download/?bined-intellij-plugin.zip

Plugin support 3 modes:

To switch between memory and delta mode go to IntelliJ Settings/Tools/BinEd Plugin/Editor - File handling mode. There are still various bugs present in current development build, but basic editing should be hopefully working.

viktordoronin commented 9 months ago

Still having this issue to this day, no idea if the fixes are in the current release or not yet. I'm not an expert on Java, but can't you just close the file handle when the tab is closed? That's what I ended up doing manually in process explorer to fix the issue.

hajdam commented 9 months ago

I guess I could publish a release with fixes even thou there is various unfinished / in-progress functionality...

hajdam commented 9 months ago

Released version 0.2.9 where this should be fixed / mitigated so that on Windows:

lppedd commented 9 months ago

Thank you!