From 13885b73dd26bb04884b315534b0da9d82253f8e Mon Sep 17 00:00:00 2001 From: Martijn Coenen Date: Wed, 11 Mar 2020 13:38:19 +0100 Subject: Use REPLACE_EXISTING for rename(2) workaround. We implement a workaround for Os.rename() failing with EXDEV, by using Files.move() instead. However, since we didn't pass in REPLACE_EXISTING as an option, Files.move() would fail if the destination file already existed. Since the semantics of rename(2) are to replace a file if it already exists, the work-around should do the same; so pass the flag. Also, log if the workaround throws an exception; that would have made this easier to debug. Bug: 151078664 Test: atest com.android.tests.fused.host.FuseDaemonHostTest#testRenameAndReplaceFile Change-Id: Ie84e89f857c2cc71e3b373db2032f700d066cf6b --- core/java/android/app/ActivityThread.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'core/java/android/app/ActivityThread.java') diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index a62f0a6807bb..bd3fee2d1fc7 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -201,6 +201,7 @@ import java.lang.reflect.Method; import java.net.InetAddress; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.StandardCopyOption; import java.text.DateFormat; import java.util.ArrayList; import java.util.Arrays; @@ -7413,8 +7414,10 @@ public final class ActivityThread extends ClientTransactionHandler { if (e.errno == OsConstants.EXDEV && oldPath.startsWith("/storage/")) { Log.v(TAG, "Recovering failed rename " + oldPath + " to " + newPath); try { - Files.move(new File(oldPath).toPath(), new File(newPath).toPath()); + Files.move(new File(oldPath).toPath(), new File(newPath).toPath(), + StandardCopyOption.REPLACE_EXISTING); } catch (IOException e2) { + Log.e(TAG, "Rename recovery failed ", e); throw e; } } else { -- cgit v1.2.3