am 7a51b14d: am 094e3e0b: Merge change Icb89d482 into eclair

Merge commit '7a51b14d9f7f8c48c74ed1787bed3ef83aae6658'

* commit '7a51b14d9f7f8c48c74ed1787bed3ef83aae6658':
  Check if rename of backed up file fails before persisting new changes.
This commit is contained in:
Suchi Amalapurapu
2009-10-01 12:23:14 -07:00
committed by Android Git Automerger
5 changed files with 31 additions and 9 deletions

View File

@@ -2760,6 +2760,7 @@ class ApplicationContext extends Context {
if (mFile.exists()) {
if (!mFile.renameTo(mBackupFile)) {
Log.e(TAG, "Couldn't rename file " + mFile + " to backup file " + mBackupFile);
return false;
}
}

View File

@@ -2988,7 +2988,10 @@ public final class BatteryStatsImpl extends BatteryStats {
if (mBackupFile.exists()) {
mBackupFile.delete();
}
mFile.renameTo(mBackupFile);
if (!mFile.renameTo(mBackupFile)) {
Log.w("BatteryStats", "Failed to back up file before writing new stats");
return;
}
}
try {
@@ -3003,8 +3006,14 @@ public final class BatteryStatsImpl extends BatteryStats {
mBackupFile.delete();
mLastWriteTime = SystemClock.elapsedRealtime();
return;
} catch (IOException e) {
Log.e("BatteryStats", "Error writing battery statistics", e);
Log.w("BatteryStats", "Error writing battery statistics", e);
}
if (mFile.exists()) {
if (!mFile.delete()) {
Log.w(TAG, "Failed to delete mangled file " + mFile);
}
}
}