From 44278d1b6bad228acaa7c2ada01ff816798c9821 Mon Sep 17 00:00:00 2001 From: Hristo Stoyanov Date: Mon, 14 Sep 2020 16:55:41 -0700 Subject: [PATCH 1/2] Make global shutdown hook optional, in a backward compatible way. Closes #54. --- .../dev/dokan/dokan_java/AbstractDokanyFileSystem.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/dokan/dokan_java/AbstractDokanyFileSystem.java b/src/main/java/dev/dokan/dokan_java/AbstractDokanyFileSystem.java index 613c6424..d5c60f40 100644 --- a/src/main/java/dev/dokan/dokan_java/AbstractDokanyFileSystem.java +++ b/src/main/java/dev/dokan/dokan_java/AbstractDokanyFileSystem.java @@ -30,6 +30,7 @@ public abstract class AbstractDokanyFileSystem implements DokanyFileSystem { protected final FileSystemInformation fileSystemInformation; protected final DokanyOperations dokanyOperations; protected final boolean usesKernelFlagsAndCodes; + protected final boolean installShutdownHook; protected Path mountPoint; protected String volumeName; protected int volumeSerialnumber; @@ -38,14 +39,19 @@ public abstract class AbstractDokanyFileSystem implements DokanyFileSystem { private final AtomicBoolean isMounted; private Set notImplementedMethods; - public AbstractDokanyFileSystem(FileSystemInformation fileSystemInformation, boolean usesKernelFlagsAndCodes) { + public AbstractDokanyFileSystem(FileSystemInformation fileSystemInformation, boolean usesKernelFlagsAndCodes, boolean installShutdownHook) { this.fileSystemInformation = fileSystemInformation; this.usesKernelFlagsAndCodes = usesKernelFlagsAndCodes; + this.installShutdownHook = installShutdownHook; this.isMounted = new AtomicBoolean(false); this.dokanyOperations = new DokanyOperations(); init(dokanyOperations); } + public AbstractDokanyFileSystem(FileSystemInformation fileSystemInformation, boolean usesKernelFlagsAndCodes) { + this(fileSystemInformation,usesKernelFlagsAndCodes,true); + } + private void init(DokanyOperations dokanyOperations) { notImplementedMethods = Arrays.stream(getClass().getMethods()) .filter(method -> method.getAnnotation(NotImplemented.class) != null) @@ -247,7 +253,7 @@ public final synchronized void mount(Path mountPoint, String volumeName, int vol try { int mountStatus; - if (DokanyUtils.canHandleShutdownHooks()) { + if (installShutdownHook && DokanyUtils.canHandleShutdownHooks()) { Runtime.getRuntime().addShutdownHook(new Thread(this::unmount)); } From 58f6c700dee4c539d163889883b28d32e7124c06 Mon Sep 17 00:00:00 2001 From: Hristo Stoyanov Date: Mon, 14 Sep 2020 17:33:40 -0700 Subject: [PATCH 2/2] Make global shutdown hook optional, in a backward compatible way. Closes #54. --- .../java/dev/dokan/dokan_java/DokanyFileSystemStub.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/dokan/dokan_java/DokanyFileSystemStub.java b/src/main/java/dev/dokan/dokan_java/DokanyFileSystemStub.java index c778b7c2..4b38518a 100644 --- a/src/main/java/dev/dokan/dokan_java/DokanyFileSystemStub.java +++ b/src/main/java/dev/dokan/dokan_java/DokanyFileSystemStub.java @@ -1,12 +1,12 @@ package dev.dokan.dokan_java; -import dev.dokan.dokan_java.structure.ByHandleFileInformation; -import dev.dokan.dokan_java.structure.DokanFileInfo; import com.sun.jna.Pointer; import com.sun.jna.WString; import com.sun.jna.platform.win32.WinBase; import com.sun.jna.ptr.IntByReference; import com.sun.jna.ptr.LongByReference; +import dev.dokan.dokan_java.structure.ByHandleFileInformation; +import dev.dokan.dokan_java.structure.DokanFileInfo; public class DokanyFileSystemStub extends AbstractDokanyFileSystem { @@ -14,6 +14,10 @@ public DokanyFileSystemStub(FileSystemInformation fileSystemInformation, boolean super(fileSystemInformation, usesKernelFlagsAndCodes); } + public DokanyFileSystemStub(FileSystemInformation fileSystemInformation, boolean usesKernelFlagsAndCodes, boolean installShutdownHook) { + super(fileSystemInformation, usesKernelFlagsAndCodes,installShutdownHook); + } + /** * {@inheritDoc} *