diff options
author | Elliott Hughes <enh@google.com> | 2012-11-05 13:45:17 -0800 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2012-11-05 13:45:17 -0800 |
commit | 028ad9ba399b09050866e6b369f6e72879b45b3a (patch) | |
tree | 838b95a14e346c4d86c6e4761b50f1a77b535947 /dalvik | |
parent | 288a1a268bf01d2c88aa65b90e1f4cd75e6f584f (diff) | |
parent | df0d029524bc6f4aa6212e8d0e337b590731c7a4 (diff) | |
download | libcore-028ad9ba399b09050866e6b369f6e72879b45b3a.zip libcore-028ad9ba399b09050866e6b369f6e72879b45b3a.tar.gz libcore-028ad9ba399b09050866e6b369f6e72879b45b3a.tar.bz2 |
am df0d0295: Merge "Make System.loadLibrary use open(2) rather than stat(2)."
* commit 'df0d029524bc6f4aa6212e8d0e337b590731c7a4':
Make System.loadLibrary use open(2) rather than stat(2).
Diffstat (limited to 'dalvik')
-rw-r--r-- | dalvik/src/main/java/dalvik/system/DexPathList.java | 47 |
1 files changed, 17 insertions, 30 deletions
diff --git a/dalvik/src/main/java/dalvik/system/DexPathList.java b/dalvik/src/main/java/dalvik/system/DexPathList.java index 1253223..048cc83 100644 --- a/dalvik/src/main/java/dalvik/system/DexPathList.java +++ b/dalvik/src/main/java/dalvik/system/DexPathList.java @@ -25,6 +25,11 @@ import java.util.Collections; import java.util.Enumeration; import java.util.regex.Pattern; import java.util.zip.ZipFile; +import libcore.io.ErrnoException; +import libcore.io.IoUtils; +import libcore.io.Libcore; +import libcore.io.StructStat; +import static libcore.io.OsConstants.*; /** * A pair of lists of entries, associated with a {@code ClassLoader}. @@ -154,36 +159,20 @@ import java.util.zip.ZipFile; * Helper for {@link #splitPaths}, which does the actual splitting * and filtering and adding to a result. */ - private static void splitAndAdd(String path, boolean wantDirectories, + private static void splitAndAdd(String searchPath, boolean wantDirectories, ArrayList<File> resultList) { - if (path == null) { + if (searchPath == null) { return; } - - String[] strings = path.split(Pattern.quote(File.pathSeparator)); - - for (String s : strings) { - File file = new File(s); - - if (! (file.exists() && file.canRead())) { - continue; - } - - /* - * Note: There are other entities in filesystems than - * regular files and directories. - */ - if (wantDirectories) { - if (!file.isDirectory()) { - continue; - } - } else { - if (!file.isFile()) { - continue; + for (String path : searchPath.split(":")) { + try { + StructStat sb = Libcore.os.stat(path); + if ((wantDirectories && S_ISDIR(sb.st_mode)) || + (!wantDirectories && S_ISREG(sb.st_mode))) { + resultList.add(new File(path)); } + } catch (ErrnoException ignored) { } - - resultList.add(file); } } @@ -370,14 +359,12 @@ import java.util.zip.ZipFile; */ public String findLibrary(String libraryName) { String fileName = System.mapLibraryName(libraryName); - for (File directory : nativeLibraryDirectories) { - File file = new File(directory, fileName); - if (file.exists() && file.isFile() && file.canRead()) { - return file.getPath(); + String path = new File(directory, fileName).getPath(); + if (IoUtils.canOpenReadOnly(path)) { + return path; } } - return null; } |