Class WindowsEmulatingFileSystem
- All Implemented Interfaces:
ForwardingObject<FileSystem>
,Closeable
,AutoCloseable
ForwardingFileSystem
that emulates Windows' behaviour regarding the deletion of files
with open handles. Only file handles acquired through FileChannel
and
AsynchronousFileChannel
are tracked.
On Windows, deleting files while they're open isn't allowed by default. One has to open the
file with FILE_SHARE_DELETE for that to work. Luckily, NIO opens file channels as such. The
problem is when a file is requested for deletion while having open handles, Windows only
guarantees it gets physically deleted after all its open handles are closed. In the meantime, the
OS denies access to that file. Since Windows associates handles with file names
(https://devblogs.microsoft.com/oldnewthing/20040607-00/?p=38993), the deleted file name is hence
retained till all handles to that file are closed. Things like creating a new file with the name
of a file marked for deletion, renaming another file to such name or opening any sort of channel
to such file all throw AccessDeniedException
. This file system emulates that behavior, so
we're sure these cases are covered when interacting with files on Windows.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
delegate()
getPathMatcher
(String syntaxAndPattern) boolean
isOpen()
boolean
com.github.mizosoft.methanol.testing.file.FileSystemProviderWrapper
provider()
static FileSystem
wrap
(FileSystem delegate)
-
Method Details
-
wrap
-
provider
public com.github.mizosoft.methanol.testing.file.FileSystemProviderWrapper provider() -
getRootDirectories
-
getPath
-
delegate
- Specified by:
delegate
in interfaceForwardingObject<FileSystem>
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classFileSystem
- Throws:
IOException
-
isOpen
public boolean isOpen()- Specified by:
isOpen
in classFileSystem
-
isReadOnly
public boolean isReadOnly()- Specified by:
isReadOnly
in classFileSystem
-
getSeparator
- Specified by:
getSeparator
in classFileSystem
-
getFileStores
- Specified by:
getFileStores
in classFileSystem
-
supportedFileAttributeViews
- Specified by:
supportedFileAttributeViews
in classFileSystem
-
getPathMatcher
- Specified by:
getPathMatcher
in classFileSystem
-
getUserPrincipalLookupService
- Specified by:
getUserPrincipalLookupService
in classFileSystem
-
newWatchService
- Specified by:
newWatchService
in classFileSystem
- Throws:
IOException
-