Workaround mkdirs concurency problems
Use only mkdir since our usage is a simple case.
Bug: https://code.google.com/p/android/issues/detail?id=79388
Change-Id: Iab7504f3c38c660f93ab1249895be454af5ff84d
diff --git a/library/src/android/support/multidex/MultiDexExtractor.java b/library/src/android/support/multidex/MultiDexExtractor.java
index b5973c5..27da6b3 100644
--- a/library/src/android/support/multidex/MultiDexExtractor.java
+++ b/library/src/android/support/multidex/MultiDexExtractor.java
@@ -253,10 +253,12 @@
*/
private static void prepareDexDir(File dexDir, final String extractedFilePrefix)
throws IOException {
- dexDir.mkdirs();
- if (!dexDir.isDirectory()) {
- throw new IOException("Failed to create dex directory " + dexDir.getPath());
- }
+ /* mkdirs() has some bugs, especially before jb-mr1 and we have only a maximum of one parent
+ * to create, lets stick to mkdir().
+ */
+ File cache = dexDir.getParentFile();
+ mkdirChecked(cache);
+ mkdirChecked(dexDir);
// Clean possible old files
FileFilter filter = new FileFilter() {
@@ -282,6 +284,24 @@
}
}
+ private static void mkdirChecked(File dir) throws IOException {
+ dir.mkdir();
+ if (!dir.isDirectory()) {
+ File parent = dir.getParentFile();
+ if (parent == null) {
+ Log.e(TAG, "Failed to create dir " + dir.getPath() + ". Parent file is null.");
+ } else {
+ Log.e(TAG, "Failed to create dir " + dir.getPath() +
+ ". parent file is a dir " + parent.isDirectory() +
+ ", a file " + parent.isFile() +
+ ", exists " + parent.exists() +
+ ", readable " + parent.canRead() +
+ ", writable " + parent.canWrite());
+ }
+ throw new IOException("Failed to create cache directory " + dir.getPath());
+ }
+ }
+
private static void extract(ZipFile apk, ZipEntry dexFile, File extractTo,
String extractedFilePrefix) throws IOException, FileNotFoundException {