Merge "Remove pre-N db after successful migration" into nyc-dev

am: cdb5fcf7b8

* commit 'cdb5fcf7b81de81793995097b017c001be2a4264':
  Remove pre-N db after successful migration

Change-Id: I343eb6688340bfca5b1ee16a6a85bf1f3e5c7632
This commit is contained in:
Fyodor Kupolov
2016-04-21 20:35:02 +00:00
committed by android-build-merger

View File

@@ -4696,26 +4696,20 @@ public class AccountManagerService
ceHelper.getWritableDatabase();
ceHelper.close();
if (removeOldDb) {
// TODO STOPSHIP - backup file during testing. Remove file before the release
Log.i(TAG, "Migration complete - creating backup of old db " + preNDatabaseFile);
renameToBakFile(preNDatabaseFile);
Slog.i(TAG, "Migration complete - removing pre-N db " + preNDatabaseFile);
if (!SQLiteDatabase.deleteDatabase(preNDatabaseFile)) {
Slog.e(TAG, "Cannot remove pre-N db " + preNDatabaseFile);
}
}
return ceHelper;
}
private static void renameToBakFile(File file) {
File bakFile = new File(file.getPath() + ".bak");
if (!file.renameTo(bakFile)) {
Log.e(TAG, "Cannot move file to " + bakFile);
}
}
private static boolean migratePreNDbToCe(File oldDbFile, File ceDbFile) {
Log.i(TAG, "Moving pre-N DB " + oldDbFile + " to CE " + ceDbFile);
Slog.i(TAG, "Moving pre-N DB " + oldDbFile + " to CE " + ceDbFile);
try {
FileUtils.copyFileOrThrow(oldDbFile, ceDbFile);
} catch (IOException e) {
Log.e(TAG, "Cannot copy file to " + ceDbFile + " from " + oldDbFile, e);
Slog.e(TAG, "Cannot copy file to " + ceDbFile + " from " + oldDbFile, e);
// Try to remove potentially damaged file if I/O error occurred
deleteDbFileWarnIfFailed(ceDbFile);
return false;