Skip to content

Commit

Permalink
8322881: Method createTempFile() causes file copy permission issue wh…
Browse files Browse the repository at this point in the history
…en running through jtreg
  • Loading branch information
yaqsun committed Feb 23, 2024
1 parent d666698 commit 22fcacd
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions test/jdk/java/nio/file/Files/CopyMoveVariations.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -70,17 +70,17 @@ enum PathType {
private static final boolean SUPPORTS_POSIX_PERMISSIONS;

static {
Path tmp = null;
Path currentDir = null;
try {
tmp = Files.createTempFile(Path.of("."), "this", "that");
currentDir = Files.createTempFile(Path.of("."), "this", "that");
SUPPORTS_POSIX_PERMISSIONS =
Files.getFileStore(tmp).supportsFileAttributeView("posix");
Files.getFileStore(currentDir).supportsFileAttributeView("posix");
} catch (IOException cause) {
throw new UncheckedIOException(cause);
} finally {
if (tmp != null) {
if (currentDir != null) {
try {
Files.delete(tmp);
Files.delete(currentDir);
} catch (IOException ignore) {
}
}
Expand Down Expand Up @@ -142,15 +142,15 @@ void op(OpType op, PathType type, String mode, boolean replaceExisting,
Path source = null;
Path target = null;
Path linkTarget = null;
Path current = Path.of(".");
Path currentDir = Path.of(".");
try {
switch (type) {
case FILE ->
source = Files.createTempFile(current, "file", "dat");
source = Files.createTempFile(currentDir, "file", "dat");
case DIR ->
source = Files.createTempDirectory(current, "dir");
source = Files.createTempDirectory(currentDir, "dir");
case LINK -> {
linkTarget = Files.createTempFile(current, "link", "target");
linkTarget = Files.createTempFile(currentDir, "link", "target");
Path link = Path.of("link");
source = Files.createSymbolicLink(link, linkTarget);
}
Expand All @@ -164,7 +164,7 @@ void op(OpType op, PathType type, String mode, boolean replaceExisting,
Files.setPosixFilePermissions(source, perms);

if (targetExists)
target = Files.createTempFile(current, "file", "target");
target = Files.createTempFile(currentDir, "file", "target");
else
target = Path.of("target");

Expand Down

0 comments on commit 22fcacd

Please sign in to comment.