SerCeMan / jnr-fuse

FUSE implementation in Java using Java Native Runtime (JNR)
MIT License
365 stars 87 forks source link

Unable to find WinFsp dynamically resulting in a crash #37

Closed APayerl closed 6 years ago

APayerl commented 6 years ago

When WinFsp is not installed in C: (or any other non default location) on Windows jnr-fuse will crash since unable to find the library. Should be changed to locate the install path dynamically instead of hardcoded string. Row 64 in AbstractFuseFS.class in package ru.serce.jnrfuse.

SerCeMan commented 6 years ago

Hi, @APayerl!

Thank you for reporting the issue. What do you mean by locating the install path dynamically? I have a limited experience with Windows and unfortunately, don't know any standard approaches for that.

I agree that it's better to check the existence of the file and throw an exception if it doesn't exist. But please send a PR if you have a better idea of handling such situations.

APayerl commented 6 years ago

I have not thought that much about it so unfortunately I don't have a solution.. but maybe check what driveletters are plugged in atm File[] roots = File.listRoots(); and check the most probable locations

boolean foundInstall = false;
for(File path : roots) {
    newPath = path + "\\Program Files (x86)\\WinFsp\\bin\\winfsp-x64.dll";
    if(isPathCorrect(newPath)) {
        foundInstall = true;
        break;
    }
}

Something like that... Of course it would not be the most effective solution but it would probably be an improvement.

tfiskgul commented 6 years ago

@APayerl It is possible to set the property called "jnrfuse.winfsp.path" to the correct value?

https://github.com/SerCeMan/jnr-fuse/blob/cd33bdf184c8480103629a2452e41802a1a0190f/src/main/java/ru/serce/jnrfuse/AbstractFuseFS.java#L64

APayerl commented 6 years ago

Yea well I suppose it should work if WinFsp sets a key(I have no clue if they do).. If not then a solution like this would work(even though a tad excessive for this purpose):

private File findFile(File start, String goal) {
    File file = null;
    if(start.isDirectory()) {
        for(File f: start.listFiles()) {
            file = findFile(f, goal);
            if(file != null) {
                break;
            }
        }
    } else {
        file = start.getName().equals(goal) ? start : null;
    }
    return file;
}
SerCeMan commented 6 years ago

@tfiskgul I added the jnrfuse.winfsp.path property check for that purpose. So that you can provide a winfsp path if it is not standard as a workaround.

@APayerl I don't think that scanning the whole filesystem is a viable solution.

I guess that the best way to implement this is to do a registry lookup, it seems like winfsp uses the Software\\WinFsp key. Like it's implemented in the cgofuse, https://github.com/billziss-gh/cgofuse/blob/master/fuse/host.go#L95.

Unfortunately, I won't be able to devote enough time to work on it soon, but I'll be happy to provide as much help as I can if someone wants to send a PR.

APayerl commented 6 years ago

On my machine I found the key HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\WinFsp\InstallDir pointing to the folder where it was installed. Ofcourse this was since I use 64bit Windows.

Have a fix ready but unable to push it. (new to open source contributions)

SerCeMan commented 6 years ago

Hey, @APayerl! There are some good instructions here, https://opensource.guide/how-to-contribute/#opening-a-pull-request. Also, if you can't for some reasons contribute to github (I know that some companies don't allow this), you can post the code here.