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

IllegalArgumentException thrown with CifsFile returned by getParentFile on root #153

Closed
zerikv opened this issue Feb 4, 2015 · 2 comments

Comments

@zerikv
Copy link
Contributor

zerikv commented Feb 4, 2015

Hi,

I have a little problem with the implementation CifsFile.getParentFile().

The contract in the interface OverthereFile says:

    @return the parent of this file or <code>null</code> if this file does not have a parent file.

But with a SMB File, the method CifsFile.getParentFile() doesn't return null for a root path (like \\host\$C).

The path of the SmbFile returned is \\host, smbFile.getParent() doesn't throw a MalformedURLException.

Call next the method CifsFile.getPath() on such SmbFile throws the following exception:

java.lang.IllegalArgumentException: UNC path '\\EVE-WIN8' did not match expected expression '\\\\[^\\]+\\([^\\]+(?:\\.*)?)'
    at com.xebialabs.overthere.cifs.PathEncoder.fromUncPath(PathEncoder.java:113)
    at com.xebialabs.overthere.cifs.CifsFile.getPath(CifsFile.java:58)
    at com.xebialabs.overthere.cifs.CifsFile.toString(CifsFile.java:398)

To workaround this issue, I've patched the method CifsFile.getParentFile() like that:

    @Override
    public OverthereFile getParentFile() {
        try {
            CifsFile parentFile = new CifsFile(getConnection(), new SmbFile(smbFile.getParent(), connection.authentication));
            parentFile.getPath();
            return parentFile;
        } catch (MalformedURLException exc) {
            return null;
        } catch (IllegalArgumentException exc) {
            return null;
        }
    }

Regards,
Eric

@zerikv
Copy link
Contributor Author

zerikv commented Feb 25, 2015

Sorry but I met a problem with this fix, the method smbFile.getParent() returns a smb URL (like: smb://host/C$/folder), it isn't an UNC path thus the test with PathEncoder.isValidUncPath is always false.

@hierynomus
Copy link
Contributor

@zerikv This should now be correctly patched, can you check?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants