Skip to content
Open
Changes from 1 commit
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: 10 additions & 8 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 @@ -27,6 +27,7 @@

import java.io.InputStream;
import java.io.IOException;
import java.nio.file.FileStore;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.BasicFileAttributeView;
import java.nio.file.attribute.PosixFileAttributes;
Expand Down Expand Up @@ -109,17 +110,19 @@ 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.

FileSystemProvider provider = source.getFileSystem().provider();

// retrieve whether source posix view is supported
FileStore fileStore = provider.getFileStore(source);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm concerned this will add overhead to each copy operation. There shouldn't be any need to use FileStore in this method. If the provider supports the the POSIX view then this method can use it.

Copy link
Contributor

Choose a reason for hiding this comment

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

So I think the summary is the JBS issue isn't really a bug, it's more than using sourcePosixView instead of boolean is confusing when looking at this code.

boolean sourceSupportsPosixFileAttributeView =
fileStore.supportsFileAttributeView(PosixFileAttributeView.class);

// attributes of source file
BasicFileAttributes sourceAttrs = null;
if (sourcePosixView != null) {
if (sourceSupportsPosixFileAttributeView)
sourceAttrs = Files.readAttributes(source,
PosixFileAttributes.class,
linkOptions);
}
if (sourceAttrs == null)
Copy link
Contributor

Choose a reason for hiding this comment

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

This could if-then-else too.

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 could if-then-else too.

Since if the posix view is supported, then sourceAttrs could not be null here, correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, but it can be simplified to if (sourceSupportsPosixAttributes) { .. } else { ..}. What you have is okay too.

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 can be simplified

So changed in e76d298.

sourceAttrs = Files.readAttributes(source,
BasicFileAttributes.class,
Expand All @@ -130,7 +133,6 @@ static void copyToForeignTarget(Path source, Path target,
throw new IOException("Copying of symbolic links not supported");

// ensure source can be copied
FileSystemProvider provider = source.getFileSystem().provider();
provider.checkAccess(source, AccessMode.READ);

// delete target if it exists and REPLACE_EXISTING is specified
Expand All @@ -151,7 +153,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 (sourceSupportsPosixFileAttributeView) {
targetView = Files.getFileAttributeView(target,
PosixFileAttributeView.class);
}
Expand Down