cryptomator / fuse-cloud-access-adapter

FUSE access to cloud-access-java
GNU Affero General Public License v3.0
2 stars 1 forks source link

ClosedChannelException is thrown when a previously unlinked file is created again #4

Closed infeo closed 4 years ago

infeo commented 4 years ago

Library: WinFSP 1.7 OS: Windows 10 Pro 2004

If a file is opend/created, then deleted and after the release created again, any attempt of reading/writing to the file (i.e. all actions requiring a file channel) will fail and a ClosedChannelException is thrown.

This can be easily tested by using the LocalFsProvider, mirroring a directory and then saving a new file with the Notepad application in the mirror. This app performs the aforementioned sequence of action and therefore fails with an I/O-Error message.

infeo commented 4 years ago

The following code provides a unit test:

@Test
@DisplayName("simulates Notepad's access pattern during save of a new File")
void testWindowsNotepadSavePatternForNewFiles() {
    FuseFileInfo fi1 = TestFileInfo.create();
    FileStat stat = TestFileStat.create();
    String p = "/foo.txt";
    int code = fs.getattr(p,stat);

    assert code == -ErrorCodes.ENOENT();

    fs.create(p,0644,fi1);
    fs.release(p,fi1);

    FuseFileInfo fi2 = TestFileInfo.create();
    fs.open(p,fi2);
    fs.unlink(p);
    fs.release(p,fi2);

    FuseFileInfo fi3 = TestFileInfo.create();
    fs.create(p,0644, fi3);
    Assertions.assertEquals(0, fs.getattr(p,stat));
}