Skip to content

Commit 0db77f6

Browse files
committed
[Win32] Fix deletion of read-only files not working with Java 25 #2178
With Java 25, the behavior of File#delete() has been changed for read-only files on Windows. Previously, the operation also removed read-only files whereas now the operation fails in that case. LocalFile#delete() depends on the preexisting behavior. It ensures that read-only files are also deleted. In order to preserve the behavior with Java 25, this change makes LocalFile#delete() explicitly remove the read-only attribute when deleting a read-only file on WIndows. Fixes #2178
1 parent 30180a8 commit 0db77f6

File tree

1 file changed

+7
-0
lines changed
  • resources/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local

1 file changed

+7
-0
lines changed

resources/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/LocalFile.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import org.eclipse.core.runtime.MultiStatus;
6262
import org.eclipse.core.runtime.NullProgressMonitor;
6363
import org.eclipse.core.runtime.OperationCanceledException;
64+
import org.eclipse.core.runtime.Platform.OS;
6465
import org.eclipse.core.runtime.Status;
6566
import org.eclipse.core.runtime.SubMonitor;
6667
import org.eclipse.osgi.util.NLS;
@@ -314,6 +315,12 @@ private IStatus internalDelete(File target, InfiniteProgress infMonitor, Executo
314315
} catch (AccessDeniedException e) {
315316
// If the file is read only, it can't be deleted via Files.deleteIfExists()
316317
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=500306
318+
// Since Java 25, just calling File#delete() is not sufficient anymore on Windows
319+
// but the read-only state has to be cleared explicitly,
320+
// see https://bugs.openjdk.org/browse/JDK-8355954
321+
if (OS.isWindows()) {
322+
target.setWritable(true);
323+
}
317324
if (target.delete()) {
318325
infMonitor.worked();
319326
return Status.OK_STATUS;

0 commit comments

Comments
 (0)