Merge commit '7a51b14d9f7f8c48c74ed1787bed3ef83aae6658' * commit '7a51b14d9f7f8c48c74ed1787bed3ef83aae6658': Check if rename of backed up file fails before persisting new changes.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user