Skip to content

Commit

Permalink
Make global shutdown hook optional, in a backward compatible way. Closes
Browse files Browse the repository at this point in the history
  • Loading branch information
hrstoyanov committed Sep 14, 2020
1 parent ec33deb commit 44278d1
Showing 1 changed file with 8 additions and 2 deletions.
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

0 comments on commit 44278d1

Please sign in to comment.