Skip to content
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/java.base/share/classes/java/nio/file/CopyMoveHelper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2025, 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 @@ -109,21 +109,21 @@ static void copyToForeignTarget(Path source, Path target,
LinkOption[] linkOptions = (opts.followLinks) ? new LinkOption[0] :
new LinkOption[] { LinkOption.NOFOLLOW_LINKS };

// retrieve source posix view, null if unsupported
final PosixFileAttributeView sourcePosixView =
Files.getFileAttributeView(source, PosixFileAttributeView.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should delete this. Instead, I think we can initialize sourceSupportsPosixAttributes with Files.getFileAttributeView(source, PosixFileAttributeView.class) != null.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think we should delete this

So changed in ad29084.


// attributes of source file
boolean sourceSupportsPosixAttributes = false;
BasicFileAttributes sourceAttrs = null;
if (sourcePosixView != null) {
try {
sourceAttrs = Files.readAttributes(source,
PosixFileAttributes.class,
linkOptions);
}
if (sourceAttrs == null)
sourceSupportsPosixAttributes = true;
} catch (UnsupportedOperationException x) {
// posix attributes not supported
sourceAttrs = Files.readAttributes(source,
BasicFileAttributes.class,
linkOptions);
}

assert sourceAttrs != null;

if (sourceAttrs.isSymbolicLink())
Expand Down Expand Up @@ -151,7 +151,7 @@ else if (Files.exists(target))
// copy basic and, if supported, POSIX attributes to target
if (opts.copyAttributes) {
BasicFileAttributeView targetView = null;
if (sourcePosixView != null) {
if (sourceSupportsPosixAttributes) {
targetView = Files.getFileAttributeView(target,
PosixFileAttributeView.class);
}
Expand Down