diff options
author | Sven Gothel <[email protected]> | 2020-08-26 01:09:03 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-08-26 01:09:03 +0200 |
commit | 12e648b8e97292fe5438eb27e1d4618728a7061e (patch) | |
tree | ef8489f1d76eb89a2ca22accab0c07b569923981 | |
parent | 75814b5c07733ee37b924bc34aa1e39e942e321e (diff) |
PlatformToolkit::addPath(..): Resolve complete path via File::getCanonicalPath() (absolute resolved path ) and drop duplicates
-rw-r--r-- | java/org/tinyb/PlatformToolkit.java | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/java/org/tinyb/PlatformToolkit.java b/java/org/tinyb/PlatformToolkit.java index c86f8697..7680f08c 100644 --- a/java/org/tinyb/PlatformToolkit.java +++ b/java/org/tinyb/PlatformToolkit.java @@ -206,13 +206,35 @@ final class PlatformToolkit { private static final String getPlatformName(final String libBaseName) { return prefix + libBaseName + suffix; } + private static final String getCanonicalPath(final String path) { + return AccessController.doPrivileged(new PrivilegedAction<String>() { + @Override + public String run() { + try { + final File f = new File(path); + // f.getCanonicalPath() also resolved '.', '..' and symbolic links in contrast to f.getAbsolutePath() + return f.getCanonicalPath(); + } catch (final Throwable t) { + if( BluetoothFactory.DEBUG ) { + System.err.println("getAbsolutePath("+path+") failed: "+t.getMessage()); + } + return null; + } + } } ); + } private static final void addPath(final String msg, final String path, final String platformName, final List<String> paths) { if( null != path && path.length() > 0 ) { final String fullpath = path + File.separator + platformName; - if( BluetoothFactory.DEBUG ) { - System.err.println(" "+fullpath+" (addPath "+msg+")"); + final String abspath = getCanonicalPath(fullpath); + if( null != abspath ) { + final boolean isDup = paths.contains(abspath); + if( BluetoothFactory.DEBUG ) { + System.err.println(" "+abspath+" (addPath "+msg+", dropped duplicate "+isDup+")"); + } + if( !isDup ) { + paths.add(abspath); + } } - paths.add(fullpath); } } private static final void addMultiPaths(final String msg, final String pathList, final String platformName, final List<String> paths) { |