Skip to content

Commit c6b0f99

Browse files
author
Marc Blank
committed
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
1 parent ddc421d commit c6b0f99

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

core/java/android/accounts/AccountManagerService.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1817,7 +1817,16 @@ private static String getDatabaseName(int userId) {
18171817
// Migrate old file, if it exists, to the new location
18181818
File oldFile = new File(systemDir, DATABASE_NAME);
18191819
if (oldFile.exists()) {
1820-
oldFile.renameTo(databaseFile);
1820+
// Check for use directory; create if it doesn't exist, else renameTo will fail
1821+
File userDir = new File(systemDir, "users/" + userId);
1822+
if (!userDir.exists()) {
1823+
if (!userDir.mkdirs()) {
1824+
throw new IllegalStateException("User dir cannot be created: " + userDir);
1825+
}
1826+
}
1827+
if (!oldFile.renameTo(databaseFile)) {
1828+
throw new IllegalStateException("User dir cannot be migrated: " + databaseFile);
1829+
}
18211830
}
18221831
}
18231832
return databaseFile.getPath();

0 commit comments

Comments
 (0)