From a23bb38628ac1f5dc4ebe6847faedc424dd5fce1 Mon Sep 17 00:00:00 2001 From: Amith Yamasani Date: Wed, 11 Apr 2012 15:32:07 -0700 Subject: [PATCH] Don't migrate accounts.db if already migrated. Some developers accidentally create a blank accounts.db and this was causing accounts to vanish. This safeguards the case where both old and new files exist. Bug: 6168813 Change-Id: I79cf211acc5422ff1c17fe0c9af80c49227b60ac --- core/java/android/accounts/AccountManagerService.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/java/android/accounts/AccountManagerService.java b/core/java/android/accounts/AccountManagerService.java index 197c1bd109dfb..3d5bbd485e41b 100644 --- a/core/java/android/accounts/AccountManagerService.java +++ b/core/java/android/accounts/AccountManagerService.java @@ -1844,9 +1844,12 @@ public class AccountManagerService File systemDir = Environment.getSystemSecureDirectory(); File databaseFile = new File(systemDir, "users/" + userId + "/" + DATABASE_NAME); if (userId == 0) { - // Migrate old file, if it exists, to the new location + // Migrate old file, if it exists, to the new location. + // Make sure the new file doesn't already exist. A dummy file could have been + // accidentally created in the old location, causing the new one to become corrupted + // as well. File oldFile = new File(systemDir, DATABASE_NAME); - if (oldFile.exists()) { + if (oldFile.exists() && !databaseFile.exists()) { // Check for use directory; create if it doesn't exist, else renameTo will fail File userDir = new File(systemDir, "users/" + userId); if (!userDir.exists()) {