diff options
| author | Christopher Tate <ctate@android.com> | 2009-08-03 15:38:09 -0700 |
|---|---|---|
| committer | Christopher Tate <ctate@android.com> | 2009-08-04 10:45:37 -0700 |
| commit | dfec20b10bb5cc1125217168690779d11ed8ea5a (patch) | |
| tree | 84037e2a594f03e6b7381932970e6888e95bf955 /services/java/com/android/server/BackupManagerService.java | |
| parent | 4f40b76503f3de2bbbda9e2a8b36c4e6775afc83 (diff) | |
Bootstrap the ever-backed-up bookkeeping properly
Diffstat (limited to 'services/java/com/android/server/BackupManagerService.java')
| -rw-r--r-- | services/java/com/android/server/BackupManagerService.java | 58 |
1 files changed, 32 insertions, 26 deletions
diff --git a/services/java/com/android/server/BackupManagerService.java b/services/java/com/android/server/BackupManagerService.java index 67f38163ef9f..77ba9140a03a 100644 --- a/services/java/com/android/server/BackupManagerService.java +++ b/services/java/com/android/server/BackupManagerService.java @@ -307,36 +307,42 @@ class BackupManagerService extends IBackupManager.Stub { mEverStored = new File(mBaseStateDir, "processed"); File tempProcessedFile = new File(mBaseStateDir, "processed.new"); try { - RandomAccessFile temp = new RandomAccessFile(tempProcessedFile, "rw"); - mEverStoredStream = new RandomAccessFile(mEverStored, "r"); - - // parse its existing contents - mEverStoredStream.seek(0); - temp.seek(0); - try { - while (true) { - PackageInfo info; - String pkg = mEverStoredStream.readUTF(); - try { - info = mPackageManager.getPackageInfo(pkg, 0); - mEverStoredApps.add(pkg); - temp.writeUTF(pkg); - if (DEBUG) Log.v(TAG, " + " + pkg); - } catch (NameNotFoundException e) { - // nope, this package was uninstalled; don't include it - if (DEBUG) Log.v(TAG, " - " + pkg); + // If there are previous contents, parse them out then start a new + // file to continue the recordkeeping. + if (mEverStored.exists()) { + RandomAccessFile temp = new RandomAccessFile(tempProcessedFile, "rw"); + mEverStoredStream = new RandomAccessFile(mEverStored, "r"); + + // parse its existing contents + mEverStoredStream.seek(0); + temp.seek(0); + try { + while (true) { + PackageInfo info; + String pkg = mEverStoredStream.readUTF(); + try { + info = mPackageManager.getPackageInfo(pkg, 0); + mEverStoredApps.add(pkg); + temp.writeUTF(pkg); + if (DEBUG) Log.v(TAG, " + " + pkg); + } catch (NameNotFoundException e) { + // nope, this package was uninstalled; don't include it + if (DEBUG) Log.v(TAG, " - " + pkg); + } } + } catch (EOFException e) { + // now we're at EOF } - } catch (EOFException e) { - // now we're at EOF - } - // Once we've rewritten the backup history log, atomically replace the - // old one with the new one then reopen the file for continuing use. - temp.close(); - mEverStoredStream.close(); - tempProcessedFile.renameTo(mEverStored); + // Once we've rewritten the backup history log, atomically replace the + // old one with the new one then reopen the file for continuing use. + temp.close(); + mEverStoredStream.close(); + tempProcessedFile.renameTo(mEverStored); + } + // This will create the file if it doesn't exist mEverStoredStream = new RandomAccessFile(mEverStored, "rwd"); + mEverStoredStream.seek(mEverStoredStream.length()); } catch (IOException e) { Log.e(TAG, "Unable to open known-stored file!"); mEverStoredStream = null; |
