Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make global shutdown hook optional, in a backward compatible way. #55

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/main/java/dev/dokan/dokan_java/AbstractDokanyFileSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,14 +39,19 @@ public abstract class AbstractDokanyFileSystem implements DokanyFileSystem {
private final AtomicBoolean isMounted;
private Set<String> 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)
Expand Down Expand Up @@ -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));
}

Expand Down
8 changes: 6 additions & 2 deletions src/main/java/dev/dokan/dokan_java/DokanyFileSystemStub.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
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 {

public DokanyFileSystemStub(FileSystemInformation fileSystemInformation, boolean usesKernelFlagsAndCodes) {
super(fileSystemInformation, usesKernelFlagsAndCodes);
}

public DokanyFileSystemStub(FileSystemInformation fileSystemInformation, boolean usesKernelFlagsAndCodes, boolean installShutdownHook) {
super(fileSystemInformation, usesKernelFlagsAndCodes,installShutdownHook);
}

/**
* {@inheritDoc}
*
Expand Down