Merge "Make FileUtils#createDir threadsafe" am: 5232082243
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1623101 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: I6449b55a42994f8c35854bbe698ad2c697ab0244
This commit is contained in:
@@ -1235,9 +1235,9 @@ public final class FileUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a directory with name {@code name} under an existing directory {@code baseDir}.
|
* Creates a directory with name {@code name} under an existing directory {@code baseDir} if it
|
||||||
* Returns a {@code File} object representing the directory on success, {@code null} on
|
* doesn't exist already. Returns a {@code File} object representing the directory if it exists
|
||||||
* failure.
|
* and {@code null} if not.
|
||||||
*
|
*
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@@ -1247,13 +1247,23 @@ public final class FileUtils {
|
|||||||
return createDir(dir) ? dir : null;
|
return createDir(dir) ? dir : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/**
|
||||||
|
* Ensure the given directory exists, creating it if needed. This method is threadsafe.
|
||||||
|
*
|
||||||
|
* @return false if the directory doesn't exist and couldn't be created
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
public static boolean createDir(File dir) {
|
public static boolean createDir(File dir) {
|
||||||
|
if (dir.mkdir()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (dir.exists()) {
|
if (dir.exists()) {
|
||||||
return dir.isDirectory();
|
return dir.isDirectory();
|
||||||
}
|
}
|
||||||
|
|
||||||
return dir.mkdir();
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user