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);
}
}
}

View File

@@ -816,7 +816,10 @@ class AppWidgetService extends IAppWidgetService.Stub
temp.delete();
}
writeStateToFileLocked(temp);
if (!writeStateToFileLocked(temp)) {
Log.w(TAG, "Failed to persist new settings");
return;
}
//noinspection ResultOfMethodCallIgnored
real.delete();
@@ -824,7 +827,7 @@ class AppWidgetService extends IAppWidgetService.Stub
temp.renameTo(real);
}
void writeStateToFileLocked(File file) {
boolean writeStateToFileLocked(File file) {
FileOutputStream stream = null;
int N;
@@ -877,6 +880,7 @@ class AppWidgetService extends IAppWidgetService.Stub
out.endDocument();
stream.close();
return true;
} catch (IOException e) {
try {
if (stream != null) {
@@ -889,6 +893,7 @@ class AppWidgetService extends IAppWidgetService.Stub
//noinspection ResultOfMethodCallIgnored
file.delete();
}
return false;
}
}

View File

@@ -2049,7 +2049,7 @@ class PackageManagerService extends IPackageManager.Stub {
scanMode |= SCAN_FORWARD_LOCKED;
}
File resFile = destResourceFile;
if ((scanMode & SCAN_FORWARD_LOCKED) != 0) {
if (ps != null && ((scanMode & SCAN_FORWARD_LOCKED) != 0)) {
resFile = getFwdLockedResource(ps.name);
}
// Note that we invoke the following method only if we are about to unpack an application
@@ -6529,15 +6529,19 @@ class PackageManagerService extends IPackageManager.Stub {
|FileUtils.S_IRGRP|FileUtils.S_IWGRP
|FileUtils.S_IROTH,
-1, -1);
return;
} catch(XmlPullParserException e) {
Log.w(TAG, "Unable to write package manager settings, current changes will be lost at reboot", e);
} catch(java.io.IOException e) {
Log.w(TAG, "Unable to write package manager settings, current changes will be lost at reboot", e);
}
// Clean up partially written file
if (mSettingsFilename.exists()) {
if (!mSettingsFilename.delete()) {
Log.i(TAG, "Failed to clean up mangled file: " + mSettingsFilename);
}
}
//Debug.stopMethodTracing();
}

View File

@@ -381,7 +381,10 @@ public final class UsageStatsService extends IUsageStats.Stub {
mFileLeaf = getCurrentDateStr(FILE_PREFIX);
// Copy current file to back up
File backupFile = new File(mFile.getPath() + ".bak");
mFile.renameTo(backupFile);
if (!mFile.renameTo(backupFile)) {
Log.w(TAG, "Failed to persist new stats");
return;
}
try {
// Write mStats to file
writeStatsFLOCK();