Skip to content

Conversation

@marcphilipp
Copy link
Member

@marcphilipp marcphilipp commented Feb 7, 2025

Overview

Issue: #4299


I hereby agree to the terms of the JUnit Contributor License Agreement.


Definition of Done

@marcphilipp
Copy link
Member Author

Full stacktrace of the failing test on Windows:

org.junit.platform.commons.JUnitException: Failed to close extension context
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Caused by: java.io.IOException: Failed to delete temp directory C:\Users\RUNNER~1\AppData\Local\Temp\junit-2847030605030733067. The following paths could not be deleted (see suppressed exceptions for details): <root>
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
	at java.base/java.util.stream.SortedOps$RefSortingSink.end(SortedOps.java:395)
	at java.base/java.util.stream.Sink$ChainedReference.end(Sink.java:261)
	at java.base/java.util.stream.Sink$ChainedReference.end(Sink.java:261)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:510)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
	... 3 more
	Suppressed: java.nio.file.DirectoryNotEmptyException: C:\Users\RUNNER~1\AppData\Local\Temp\junit-2847030605030733067
		at java.base/sun.nio.fs.WindowsFileSystemProvider.implDelete(WindowsFileSystemProvider.java:270)
		at java.base/sun.nio.fs.AbstractFileSystemProvider.delete(AbstractFileSystemProvider.java:105)
		at java.base/java.nio.file.Files.delete(Files.java:1153)
		at java.base/java.nio.file.Files.walkFileTree(Files.java:2816)
		at java.base/java.nio.file.Files.walkFileTree(Files.java:2870)
		... 14 more

public FileVisitResult visitFileFailed(Path file, IOException exc) {
if (exc instanceof NoSuchFileException) {
LOGGER.trace(exc, () -> "visitFileFailed: " + file);
if (exc instanceof NoSuchFileException && !Files.exists(file, LinkOption.NOFOLLOW_LINKS)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 This line fixes #4299

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It fixes the error, but it won't have deleted the junction, right?
Wouldn't it be possible to improve the implementation of fileOperations.delete() to not throw this error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It fixes the error, but it won't have deleted the junction, right?

It will be deleted by the call to resetPermissionsAndTryToDeleteAgain below.

Wouldn't it be possible to improve the implementation of fileOperations.delete() to not throw this error?

FileOperations exists only so that it can be replaced in tests.

@marcphilipp marcphilipp marked this pull request as ready for review February 7, 2025 11:30
Comment on lines +407 to +410
if (isLink(dir)) {
delete(dir);
return SKIP_SUBTREE;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 This avoids following junctions and, potentially, deleting files outside of the temp dir. We need to delete them here because postVisitDirectory is not called after returning SKIP_SUBTREE.

@marcphilipp marcphilipp changed the title Support deleting Windows junctions during temp dir cleanup Fix handling of Windows junctions during temp dir cleanup Feb 7, 2025
@marcphilipp marcphilipp merged commit 655f559 into main Feb 7, 2025
15 checks passed
@marcphilipp marcphilipp deleted the marc/4299-windows-junction-in-temp-dir branch February 7, 2025 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@TempDir cleanup does not handle Windows junctions correctly

3 participants