IllegalArgumentException thrown with CifsFile returned by getParentFile on root
zerikv opened this issue · 2 comments
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
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.
@zerikv This should now be correctly patched, can you check?