Skip to content

Commit 8f6cb15

Browse files
committed
Fix test failures of JavaHL with Java 25 on Windows due to that deleting a
file with readonly flag on Windows fails since Java 25. https://bugs.openjdk.org/browse/JDK-8355954 * subversion/bindings/javahl/tests/org/apache/subversion/javahl/SVNTests.java (createDirectories): Add `throws IOException`. (removeDirOrFile): Unset readonly flag of the file before deleting the file and add `throws IOException`. * subversion/bindings/javahl/tests/org/tigris/subversion/javahl/SVNTests.java (createDirectories, removeDirOrFile): Ditto. git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1930973 13f79535-47bb-0310-9956-ffa450edef68
1 parent 8e7ff8f commit 8f6cb15

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

subversion/bindings/javahl/tests/org/apache/subversion/javahl/SVNTests.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
import java.io.IOException;
3232
import java.net.URI;
3333
import java.net.URISyntaxException;
34+
import java.nio.file.FileStore;
35+
import java.nio.file.Files;
36+
import java.nio.file.Path;
37+
import java.nio.file.attribute.DosFileAttributeView;
3438
import java.util.Set;
3539
import java.util.HashSet;
3640
import java.util.HashMap;
@@ -287,7 +291,7 @@ protected void setUp() throws Exception
287291
* Create a directory for the sample (Greek) repository, config
288292
* files, repositories and working copies.
289293
*/
290-
private void createDirectories()
294+
private void createDirectories() throws IOException
291295
{
292296
this.rootDir.mkdirs();
293297

@@ -495,7 +499,7 @@ private File buildGreekFiles() throws IOException
495499
*
496500
* @param path The file or directory to be removed.
497501
*/
498-
static final void removeDirOrFile(File path)
502+
static final void removeDirOrFile(File path) throws IOException
499503
{
500504
if (!path.exists())
501505
{
@@ -511,6 +515,18 @@ static final void removeDirOrFile(File path)
511515
}
512516
}
513517

518+
// Unset readonly flag of the file because deleting a file with
519+
// readonly flag on Windows fails since Java 25.
520+
Path nioPath = path.toPath();
521+
FileStore store = Files.getFileStore(nioPath);
522+
if (store.supportsFileAttributeView(DosFileAttributeView.class)) {
523+
DosFileAttributeView view = Files.getFileAttributeView(
524+
nioPath, DosFileAttributeView.class);
525+
if (view != null) {
526+
view.setReadOnly(false);;
527+
}
528+
}
529+
514530
path.delete();
515531
}
516532

subversion/bindings/javahl/tests/org/tigris/subversion/javahl/SVNTests.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
import java.io.FileInputStream;
2727
import java.io.FileOutputStream;
2828
import java.io.IOException;
29+
import java.nio.file.FileStore;
30+
import java.nio.file.Files;
31+
import java.nio.file.Path;
32+
import java.nio.file.attribute.DosFileAttributeView;
2933
import java.util.HashMap;
3034
import java.util.Iterator;
3135
import java.util.Map;
@@ -245,7 +249,7 @@ protected void setUp() throws Exception
245249
* Create a directory for the sample (Greek) repository, config
246250
* files, repositories and working copies.
247251
*/
248-
private void createDirectories()
252+
private void createDirectories() throws IOException
249253
{
250254
this.rootDir.mkdirs();
251255

@@ -381,7 +385,7 @@ private File buildGreekFiles() throws IOException
381385
*
382386
* @param path The file or directory to be removed.
383387
*/
384-
static final void removeDirOrFile(File path)
388+
static final void removeDirOrFile(File path) throws IOException
385389
{
386390
if (!path.exists())
387391
{
@@ -398,6 +402,18 @@ static final void removeDirOrFile(File path)
398402
}
399403
}
400404

405+
// Unset readonly flag of the file because deleting a file with
406+
// readonly flag on Windows fails since Java 25.
407+
Path nioPath = path.toPath();
408+
FileStore store = Files.getFileStore(nioPath);
409+
if (store.supportsFileAttributeView(DosFileAttributeView.class)) {
410+
DosFileAttributeView view = Files.getFileAttributeView(
411+
nioPath, DosFileAttributeView.class);
412+
if (view != null) {
413+
view.setReadOnly(false);;
414+
}
415+
}
416+
401417
path.delete();
402418
}
403419

0 commit comments

Comments
 (0)