diff options
author | Michael Hoisie <hoisie@google.com> | 2024-04-02 08:46:56 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-04-02 08:47:38 -0700 |
commit | 7fbb1bf06b058c8cf9772727ed095242fce91bfc (patch) | |
tree | ce28a2786f83902b5c754b4ae83e12e07515254c | |
parent | b9c768d08667f228e9bf0cefa57607c8f4dd6def (diff) | |
download | robolectric-7fbb1bf06b058c8cf9772727ed095242fce91bfc.tar.gz |
Stop logging TempDirectory IOExceptions in Windows
In Windows, it is generally not possible to remove files that have been
opened in native code in the same JVM process as they were opened. Avoid
logging TempDirectory errors when files cannot be deleted. Robolectric will
attempt to delete them on its next invocation.
PiperOrigin-RevId: 621189705
-rw-r--r-- | utils/src/main/java/org/robolectric/util/TempDirectory.java | 25 | ||||
-rw-r--r-- | utils/src/test/java/org/robolectric/util/TempDirectoryTest.kt | 1 |
2 files changed, 7 insertions, 19 deletions
diff --git a/utils/src/main/java/org/robolectric/util/TempDirectory.java b/utils/src/main/java/org/robolectric/util/TempDirectory.java index b45438a05..cffcbcb59 100644 --- a/utils/src/main/java/org/robolectric/util/TempDirectory.java +++ b/utils/src/main/java/org/robolectric/util/TempDirectory.java @@ -13,10 +13,8 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; -import java.util.Arrays; import java.util.Collections; import java.util.HashSet; -import java.util.List; import java.util.Locale; import java.util.Set; import java.util.concurrent.ExecutorService; @@ -35,15 +33,6 @@ public class TempDirectory { */ private static final int DELETE_THREAD_POOL_SIZE = 5; - /** - * Assets related to the Robolectric Native Runtime (shared object files, ICU dat file, fonts) are - * extracted from a Jar file into a TempDirectory during runtime in order to be used. On Windows, - * it is not possible for the current JVM process to delete certain files due to OS constraints. - */ - @SuppressWarnings("ConstantCaseForConstants") - private static final List<String> KNOWN_WINDOWS_UNDELETEABLE_FILES = - Collections.unmodifiableList(Arrays.asList("robolectric-nativeruntime.dll", "icudt68l.dat")); - private static final String TEMP_DIR_PREFIX = "robolectric-"; static final String OBSOLETE_MARKER_FILE_NAME = ".obsolete"; @@ -153,15 +142,15 @@ public class TempDirectory { Files.delete(basePath); } catch (IOException e) { if (isWindows()) { + // Windows is much more protective of files that have been opened in native code. For + // instance, unlike in Mac and Linux, it's not possible to delete nativeruntime files + // (dlls, fonts, icu data) in the same process where they were opened. Because of + // this, we need extra cleanup logic for Windows, and we avoid logging to prevent noise + // and confusion. createFile(OBSOLETE_MARKER_FILE_NAME, ""); - // Avoid spurious logging. - for (String s : KNOWN_WINDOWS_UNDELETEABLE_FILES) { - if (e.getLocalizedMessage().contains(s)) { - return; - } - } + } else { + Logger.error("Failed to destroy temp directory", e); } - Logger.error("Failed to destroy temp directory", e); } } diff --git a/utils/src/test/java/org/robolectric/util/TempDirectoryTest.kt b/utils/src/test/java/org/robolectric/util/TempDirectoryTest.kt index 5692400c1..f9b172318 100644 --- a/utils/src/test/java/org/robolectric/util/TempDirectoryTest.kt +++ b/utils/src/test/java/org/robolectric/util/TempDirectoryTest.kt @@ -69,7 +69,6 @@ class TempDirectoryTest { if (!Files.exists(path)) { latch.countDown() } else { - System.err.println("DSP rescheduling") val ignored = service.schedule( { waitForDirectoryDeletion(path, latch, service) }, |