Skip to content

Commit b106153

Browse files
Marc BlankAndroid (Google) Code Review
authored andcommitted
Merge "Use renameTo safely when creating the user 0 account database"
2 parents bf02b98 + c6b0f99 commit b106153

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)