-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8371689: (fs) CopyMoveHelper.copyToForeignTarget use of sourcePosixView is confusing #28304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
fe0eeda
bebf4a5
ad29084
e76d298
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
|
@@ -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; | ||
|
|
@@ -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); | ||
| FileSystemProvider provider = source.getFileSystem().provider(); | ||
|
|
||
| // retrieve whether source posix view is supported | ||
| FileStore fileStore = provider.getFileStore(source); | ||
|
||
| 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) | ||
|
||
| sourceAttrs = Files.readAttributes(source, | ||
| BasicFileAttributes.class, | ||
|
|
@@ -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 | ||
|
|
@@ -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); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
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.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So changed in ad29084.