Use renameTo safely when creating the user 0 account database
* Because the user directory probably won't exist, the renameTo in previous code fails silently Bug: 6188815 Change-Id: I6afd1bad9bbd1a36de7e93d9e02ed7172b1ed370
This commit is contained in:
@@ -1817,7 +1817,16 @@ public class AccountManagerService
|
||||
// Migrate old file, if it exists, to the new location
|
||||
File oldFile = new File(systemDir, DATABASE_NAME);
|
||||
if (oldFile.exists()) {
|
||||
oldFile.renameTo(databaseFile);
|
||||
// Check for use directory; create if it doesn't exist, else renameTo will fail
|
||||
File userDir = new File(systemDir, "users/" + userId);
|
||||
if (!userDir.exists()) {
|
||||
if (!userDir.mkdirs()) {
|
||||
throw new IllegalStateException("User dir cannot be created: " + userDir);
|
||||
}
|
||||
}
|
||||
if (!oldFile.renameTo(databaseFile)) {
|
||||
throw new IllegalStateException("User dir cannot be migrated: " + databaseFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
return databaseFile.getPath();
|
||||
|
||||
Reference in New Issue
Block a user