From e3f46c56b58f40521eddb902c16de56a3bec0c68 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sat, 25 Feb 2017 20:07:47 +0800 Subject: [PATCH] Improved GVFS error logging: GVFS: %s => %s --- source/net/filebot/gio/PlatformGVFS.java | 39 +++++++++++++++--------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/source/net/filebot/gio/PlatformGVFS.java b/source/net/filebot/gio/PlatformGVFS.java index b19d3bb3..5ee5e318 100644 --- a/source/net/filebot/gio/PlatformGVFS.java +++ b/source/net/filebot/gio/PlatformGVFS.java @@ -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);