[IO-769] FileUtils copyDirectory() should NOT use COPY_ATTRIBUTES #377
Conversation
Codecov Report
@@ Coverage Diff @@
## master #377 +/- ##
============================================
+ Coverage 85.58% 85.61% +0.03%
+ Complexity 3099 3095 -4
============================================
Files 204 204
Lines 7365 7360 -5
Branches 904 901 -3
============================================
- Hits 6303 6301 -2
Misses 813 813
+ Partials 249 246 -3
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
|
See also:
|
kinow
left a comment
There was a problem hiding this comment.
Echoing @garydgregory 's words to @tresf, thanks for taking your time to prepare the PR, and for the great work.
The code looks good to me, and the rationale as well. I think @tresf 's checklist could have an extra item to verify which of the JIRA issue @garydgregory linked could be fixed by this change. I had a read of the issues, and it looks like at least a couple could be fixed by this change (or at least have a different result regarding permissions).
Cheers
Bruno
| } | ||
|
|
||
| // TODO: (Help!) Determine historically why setLastModified(File, File) needed PathUtils.setLastModifiedTime() if | ||
| // sourceFile.isFile() was true, but needed setLastModifiedTime(File, long) if sourceFile.isFile() was false |
There was a problem hiding this comment.
Thanks for adding the note. No idea why that changed, didn't have time to dig into git's history, sorry.
|
Notice that in the (old) Jira tickets above, two are about attributes not being copied, which we now do but this PR proposes to undo. So catch-22. Ideas? |
The API already offers
... however the current behavior doesn't give this control to the user, despite it being the first instinct by the community, quoting:
So if this regression is not reverted, I'd at least advocate for an API which would make the above statement correct. The current behavior silently adds |
I think we should start by reverting the change from 2.9 with this PR, and prepare a new release. I was only suggesting that someone looks at the other JIRA issues to close if it is fixed by this PR, or leave it open for the next minor or major release, as needed.
That sounds like a compromise. Probably one of the two would then have to be marked as deprecated. I don't have a large-enough Java code base that I am maintaining a the moment to measure the impact, so take my comments with a pinch of salt 🙂 No hard feelings if other options are chosen here 👍 |
|
Hello, |
|
|
|
What is the status of this PR? |
|
@tresf |
I haven't seen any new commits since my last review, so I take it if this is to be merged, it'd revert the COPY_ATTRIBUTES change. I think the last two comments reporting regressions in 2.9 now make it more complicated. If we are to revert copyDirectory, and it's confirmed copyInputStreamToFile & moveFile were also affected in 2.9, then I think it would be expected - by precedent - to revert those two too? |
This might have to do with different APIs [not] being able to set directory timestamps. |
|
The consensus, reading this PR and the ticket, is to revert the behavior, so I will merge this PR. |
|
Hello, The worst thing that there is no crash or error, it just hangs and i have infinite copying on version starting from 2.9. |
Since commons-io@2.9, the
copyDirectory()function usesCOPY_ATTRIBUTESto honor thepreserveFileDateboolean.This properly preserves the date, but introduces an inadvertent effect on file permissions.
For example, if copying from
%USERPROFILE%toC:\Program Filesthe following permissions changes can be observed.icals <file>)commons-io@2.8NT AUTHORITY\SYSTEM:(I)(F)BUILTIN\Administrators:(I)(F)BUILTIN\Users:(I)(RX)APPLICATION PACKAGE AUTHORITY\ALL APPLICATION PACKAGES:(I)(RX)APPLICATION PACKAGE AUTHORITY\ALL RESTRICTED APPLICATION PACKAGES:(I)(RX)commons-io@2.9NT AUTHORITY\SYSTEM:(F)BUILTIN\Administrators:(F)WIN10ARM\owner:(F)root:root(Linux) orroot:admin(MacOS) owned directory would inherit the target permissions. Starting with 2.9, the files will retain their original ownership.The regression can be traced to to the 2.9 release and all releases thereafter.
Prior to submitting the PR, a conversation was had on the mailing list and stackoverflow.
commons-io@1.1(2005)commons-io@2.4(2013)commons-io@2.5(2016)commons-io@2.6(2017)commons-io@2.7(2020)commons-io@2.8(2020)commons-io@2.9(2021)commons-io@2.10(2021)commons-io@2.11(2021)This PR removes the COPY_ATTRIBUTES flag unless a file is being moved (to match the OS default move behavior), and instead uses NIO calls to preserve the timestamp information.
TODO:
BasicFileAttributeView.setTimes(FileTime, FileTime, FileTime)to set ALL timestamp information. This differs slightly from pre-2.9 versions. According to the JavaDocs, this may actually set file stamps to beginning of epoch, so this may be undesired. If there's an IOException, it will fallback to the olderFile.setLastModified(long)API, but it could be argued that this should remain the only API for maximum backwards compatibility.setLastModified(File, File)needPathUtils.setLastModifiedTime()ifsourceFile.isFile()wastrue, but neededsetLastModifiedTime(File, long)ifsourceFile.isFile()wasfalse. This is the code I'm inquiring about which will be lost with this PR, so I'd like to understand the history of this to ensure we aren't introducing a regression with the new change.