Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7bb534dc authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Properly keep compatibility with openRead() during a write." into rvc-dev am: beac47b1

Change-Id: I1be214813470314cfbecb81e63d9fa64eb6f8b0f
parents e9ff69ae beac47b1
Loading
Loading
Loading
Loading
+12 −2
Original line number Original line Diff line number Diff line
@@ -227,8 +227,18 @@ public class AtomicFile {
            }
            }
        }
        }


        // Don't delete mNewName here - it was okay to call openRead() between startWrite() and
        // It was okay to call openRead() between startWrite() and finishWrite() for the first time
        // finishWrite(), and we have to keep supporting it.
        // (because there is no backup file), where openRead() would open the file being written,
        // which makes no sense, but finishWrite() would still persist the write properly. For all
        // subsequent writes, if openRead() was called in between, it would see a backup file and
        // delete the file being written, the same behavior as our new implementation. So we only
        // need a special case for the first write, and don't delete the new file in this case so
        // that finishWrite() can still work.
        if (mNewName.exists() && mBaseName.exists()) {
            if (!mNewName.delete()) {
                Log.e(LOG_TAG, "Failed to delete outdated new file " + mNewName);
            }
        }
        return new FileInputStream(mBaseName);
        return new FileInputStream(mBaseName);
    }
    }