1
1
/*
2
- * Copyright (C) 2011-2020 Samuel Audet
2
+ * Copyright (C) 2011-2022 Samuel Audet
3
3
*
4
4
* Licensed either under the Apache License, Version 2.0, or (at your option)
5
5
* under the terms of the GNU General Public License as published by
@@ -500,7 +500,7 @@ public static File cacheResource(URL resourceURL, String target) throws IOExcept
500
500
boolean reference = false ;
501
501
long size = 0 , timestamp = 0 ;
502
502
File cacheDir = getCacheDir ();
503
- File cacheSubdir = Loader . getCanonicalFile ( cacheDir ) ;
503
+ File cacheSubdir = cacheDir ;
504
504
String s = System .getProperty ("org.bytedeco.javacpp.cachedir.nosubdir" , "false" ).toLowerCase ();
505
505
boolean noSubdir = s .equals ("true" ) || s .equals ("t" ) || s .equals ("" );
506
506
URLConnection urlConnection = resourceURL .openConnection ();
@@ -661,7 +661,7 @@ public static File cacheResource(URL resourceURL, String target) throws IOExcept
661
661
}
662
662
// ... check if it has not already been extracted, and if not ...
663
663
if (!file .exists () || file .length () != size || file .lastModified () != timestamp
664
- || !cacheSubdir .equals (Loader .getCanonicalFile (file ).getParentFile ())) {
664
+ || ( canCreateSymbolicLink && !cacheSubdir .equals (Loader .getCanonicalFile (file ).getParentFile () ))) {
665
665
// ... add lock to avoid two JVMs access cacheDir simultaneously and ...
666
666
synchronized (Runtime .getRuntime ()) {
667
667
try {
@@ -672,7 +672,7 @@ public static File cacheResource(URL resourceURL, String target) throws IOExcept
672
672
lock = lockChannel .lock ();
673
673
// ... check if other JVM has extracted it before this JVM get the lock ...
674
674
if (!file .exists () || file .length () != size || file .lastModified () != timestamp
675
- || !cacheSubdir .equals (Loader .getCanonicalFile (file ).getParentFile ())) {
675
+ || ( canCreateSymbolicLink && !cacheSubdir .equals (Loader .getCanonicalFile (file ).getParentFile () ))) {
676
676
// ... extract it from our resources ...
677
677
if (logger .isDebugEnabled ()) {
678
678
logger .debug ("Extracting " + resourceURL );
@@ -790,7 +790,8 @@ public static File extractResource(URL resourceURL, File directoryOrFile,
790
790
if (entry .isDirectory ()) {
791
791
file .mkdirs ();
792
792
} else if (!cacheDirectory || !file .exists () || file .length () != entrySize
793
- || file .lastModified () != entryTimestamp || !file .equals (Loader .getCanonicalFile (file ))) {
793
+ || file .lastModified () != entryTimestamp
794
+ || (canCreateSymbolicLink && !file .equals (Loader .getCanonicalFile (file )))) {
794
795
// ... extract it from our resources ...
795
796
file .delete ();
796
797
String s = resourceURL .toString ();
@@ -937,14 +938,19 @@ public static URL[] findResources(Class cls, String name, int maxLength) throws
937
938
static Map <String ,URL []> foundLibraries = new HashMap <String ,URL []>();
938
939
/** Contains all the native libraries that we have loaded to avoid reloading them. */
939
940
static Map <String ,String > loadedLibraries = new HashMap <String ,String >();
940
- /** Will be set to false when symbolic link creation fails, such as on Windows. */
941
- static boolean canCreateSymbolicLink = true ;
942
-
941
+ /** Will be set to false when symbolic link creation fails, such as on Windows.
942
+ * Set via "org.bytedeco.javacpp.canCreateSymbolicLink" system property, defaults to false on Windows only. */
943
+ static boolean canCreateSymbolicLink = !WINDOWS ;
944
+ /** Default value for {@code load(..., pathsFirst)} set via "org.bytedeco.javacpp.pathsFirst" system property. */
943
945
static boolean pathsFirst = false ;
944
946
static {
945
947
String s = System .getProperty ("org.bytedeco.javacpp.pathsfirst" , "false" ).toLowerCase ();
946
948
s = System .getProperty ("org.bytedeco.javacpp.pathsFirst" , s ).toLowerCase ();
947
949
pathsFirst = s .equals ("true" ) || s .equals ("t" ) || s .equals ("" );
950
+
951
+ s = System .getProperty ("org.bytedeco.javacpp.cancreatesymboliclink" , WINDOWS ? "false" : "true" ).toLowerCase ();
952
+ s = System .getProperty ("org.bytedeco.javacpp.canCreateSymbolicLink" , s ).toLowerCase ();
953
+ canCreateSymbolicLink = s .equals ("true" ) || s .equals ("t" ) || s .equals ("" );
948
954
}
949
955
950
956
/** Creates and returns {@code System.getProperty("org.bytedeco.javacpp.cachedir")} or {@code ~/.javacpp/cache/} when not set. */
@@ -959,7 +965,7 @@ public static File getCacheDir() throws IOException {
959
965
File f = new File (dirName );
960
966
try {
961
967
if ((f .exists () || f .mkdirs ()) && f .canRead () && f .canWrite () && f .canExecute ()) {
962
- cacheDir = f ;
968
+ cacheDir = getCanonicalFile ( f ) ;
963
969
break ;
964
970
}
965
971
} catch (SecurityException e ) {
@@ -1246,7 +1252,7 @@ public static String load(Class cls, Properties properties, boolean pathsFirst,
1246
1252
1247
1253
String cacheDir = null ;
1248
1254
try {
1249
- cacheDir = Loader . getCanonicalPath ( getCacheDir ());
1255
+ cacheDir = getCacheDir (). toString ( );
1250
1256
} catch (IOException e ) {
1251
1257
// no cache dir, no worries
1252
1258
}
@@ -1457,6 +1463,11 @@ public static URL[] findLibrary(Class cls, ClassProperties properties, String li
1457
1463
prefix + libname2 + version2 + suffix , // Mac OS X style
1458
1464
prefix + libname2 + suffix // without version
1459
1465
};
1466
+ if (version .length () == 0 && version2 .length () == 0 ) {
1467
+ // optimize a bit for this case in particular on Windows
1468
+ styles = new String [] { prefix + libname + suffix };
1469
+ styles2 = new String [] { prefix + libname2 + suffix };
1470
+ }
1460
1471
1461
1472
String [] suffixes = properties .get ("platform.library.suffix" ).toArray (new String [0 ]);
1462
1473
if (suffixes .length > 1 ) {
0 commit comments