From 25adf3c4718092df863d3173c5066f705a04ce49 Mon Sep 17 00:00:00 2001 From: Hai Zhang Date: Tue, 19 May 2020 20:28:43 -0700 Subject: [PATCH] Don't delete the new file in openRead(). Although it may seems a left-over from a previous interrupted write, actually there are callers who call startWrite(), openRead() and then finishWrite(), and this was okay in the previous implementation, so we have to keep supporting it. The new file is virtually ignored in the new implementation, and we have no good way to know if it's actually a left-over or one that's being written, so simply leaving it there is also okay. Fixes: 157092639 Test: atest AppIdleHistoryTests#testFilesCreation Change-Id: I4dc7fde99d2b8e04356f082a6e6ad61c2835022e --- core/java/android/util/AtomicFile.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/core/java/android/util/AtomicFile.java b/core/java/android/util/AtomicFile.java index da7503d014289..1dd4cbb403db4 100644 --- a/core/java/android/util/AtomicFile.java +++ b/core/java/android/util/AtomicFile.java @@ -227,11 +227,8 @@ public class AtomicFile { } } - if (mNewName.exists()) { - if (!mNewName.delete()) { - Log.e(LOG_TAG, "Failed to delete outdated new file " + mNewName); - } - } + // Don't delete mNewName here - it was okay to call openRead() between startWrite() and + // finishWrite(), and we have to keep supporting it. return new FileInputStream(mBaseName); }