Improved GVFS error logging: GVFS: %s => %s
This commit is contained in:
parent
16a36757a7
commit
e3f46c56b5
|
@ -3,6 +3,7 @@ package net.filebot.gio;
|
|||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.util.Optional;
|
||||
|
||||
public class PlatformGVFS implements GVFS {
|
||||
|
||||
|
@ -25,23 +26,33 @@ public class PlatformGVFS implements GVFS {
|
|||
// e.g. afp://reinhard@10.0.1.5/data/Movies/Avatar.mp4 -> /run/user/1000/gvfs/afp-volume:host=10.0.1.5,user=reinhard,volume=data/Movies/Avatar.mp4
|
||||
// e.g. sftp://reinhard@10.0.1.5/home/Movies/Avatar.mp4 -> /run/user/1000/gvfs/sftp:host=10.0.1.5,user=reinhard/home/Movies/Avatar.mp4
|
||||
|
||||
String protocol = uri.getScheme();
|
||||
String host = uri.getHost();
|
||||
String user = uri.getUserInfo();
|
||||
String port = Optional.of(uri.getPort()).filter(i -> i > 0).map(Object::toString).orElse(null);
|
||||
|
||||
String path = uri.getPath().substring(1);
|
||||
String volume = null;
|
||||
|
||||
if (protocol.equals("smb") || protocol.equals("afp")) {
|
||||
volume = path.substring(0, path.indexOf('/'));
|
||||
path = path.substring(volume.length()).substring(1);
|
||||
}
|
||||
|
||||
// guess GVFS folder based on keywords (see https://wiki.gnome.org/Projects/gvfs/doc)
|
||||
for (String mount : gvfs.list()) {
|
||||
if (mount.startsWith(uri.getScheme()) && mount.contains(uri.getHost())) {
|
||||
if (uri.getUserInfo() != null && !mount.contains(uri.getUserInfo()))
|
||||
continue;
|
||||
if (uri.getPort() > 0 && !mount.contains(String.valueOf(uri.getPort())))
|
||||
continue;
|
||||
if (!mount.startsWith(protocol))
|
||||
continue;
|
||||
if (!mount.contains(host) && !(mount.endsWith("server=" + host) || mount.endsWith("host=" + host)))
|
||||
continue;
|
||||
if (volume != null && !(mount.endsWith("share=" + volume) || mount.endsWith("volume=" + volume)))
|
||||
continue;
|
||||
if (user != null && !mount.contains("user=" + user))
|
||||
continue;
|
||||
if (port != null && !mount.contains("port=" + port))
|
||||
continue;
|
||||
|
||||
String path = uri.getPath().substring(1);
|
||||
String share = path.substring(0, path.indexOf('/'));
|
||||
|
||||
if (mount.endsWith(share)) {
|
||||
path = path.substring(share.length()).substring(1);
|
||||
}
|
||||
|
||||
return new File(new File(gvfs, mount), path);
|
||||
}
|
||||
return new File(new File(gvfs, mount), path);
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("Failed to locate local path: " + uri);
|
||||
|
|
Loading…
Reference in New Issue