Skip to content
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

Made FileUtil to copy POSIX permissions #4654

Merged
merged 1 commit into from
Jan 15, 2023

Conversation

lkishalmi
Copy link
Contributor

Well as a DevOps engineer, I copy scripts and other executable inside the IDE. They lose the executable flag. That bothers me for years. Here is how I try to fix that.

Also added FileObject Path conversion methods, to make the life easier.

@lkishalmi lkishalmi added this to the NB16 milestone Sep 19, 2022
@sdedic
Copy link
Member

sdedic commented Sep 19, 2022

Two questions:

  • given that FileUtil.copy did not copy the attributes or is not specified as 'copied by stream content' ... isn't that an incompatible API change ?
  • what about the AclFileAttributesView - this is useful on Windows. Except for file owner, ACLs may be (usually) set by a regular user.

@lkishalmi
Copy link
Contributor Author

Well that API is ancient, from those times, when the Executable permissions could not be set by Java (pre-Java 6) without some magic.

As a DevOps Engineer, I'm working with a lot of scripts recently, so I thought I fix my issue when copy them in the IDE. That's all. I do not know how important Windows ACL for other people, well if that's really missed, contributions are welcome!

Copy link
Member

@mbien mbien left a comment

Choose a reason for hiding this comment

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

looks good to me - left a comment but feel free to ignore it.

Comment on lines 571 to 574
copy(bufIn, bufOut);
copyPosixPerms(source, dest);
copyAttributes(source, dest);
Copy link
Member

Choose a reason for hiding this comment

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

just a thought:
Files.copy(...) would copy posix permissions too (there is also a COPY_ATTRIBUTES option). Alternative impl would check if its an actual file first, if it is, it would use Files.copy() with paths, otherwise use streams.

Maybe its worth thinking about refreshing this code if it isn't too much work? Otherwise we end up reimplementing everything what Files.copy already does.

platform/openide.filesystems/apichanges.xml Outdated Show resolved Hide resolved
<author login="lkishalmi"/>
<compatibility addition="yes" semantic="compatible"/>
<description>
<a href="@TOP@/org/openide/filesystems/FileUtil.html#">FileUtil.copy</a> now preserves POSIX permissions if possible during file copy.
Copy link
Member

Choose a reason for hiding this comment

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

missing anchor to the FileUtil.copy chapter ?

Copy link
Contributor

@jtulach jtulach left a comment

Choose a reason for hiding this comment

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

I always dreamed about 1:1 mapping between Path and FileObject. They could delegate to each other. Always. E.g. the new methods shall never return null.

@neilcsmith-net
Copy link
Member

@lkishalmi still a few things to address here. I also agree with @mbien and @jtulach about 1:1 mapping behaviour with Path and Files::copy COPY_ATTRIBUTES. Not sure whether at least minimal things can be addressed and merged for NB16 or we should push all changes to NB17?

@lkishalmi
Copy link
Contributor Author

I hope I can make those minimal changes needed. The day is just started for me. If I can't make that happen, you are right, I'll move this to NB17.

@lkishalmi lkishalmi modified the milestones: NB16, NB17 Oct 19, 2022
@neilcsmith-net
Copy link
Member

@lkishalmi any thoughts on progressing this one? It's getting close to missing the NB17 cut too.

@lkishalmi
Copy link
Contributor Author

I always dreamed about 1:1 mapping between Path and FileObject. They could delegate to each other. Always. E.g. the new methods shall never return null.

Well, this PR won't make that dream true. Probably one day when someone would have a lot of time. AFAIK we need to provide a few FileSystem implementation to be able to use Path in all cases which are covered by FileObject.

As of returning null is in sync with the current implementation. Returning Optional would be an outlier in the API.

@lkishalmi lkishalmi added the Platform [ci] enable platform tests (platform/*) label Jan 13, 2023
@lkishalmi
Copy link
Contributor Author

Unfortunately Files.copy made other tests fail in masterfs and filesystems module. I'll revert to the previous implementation.

@lkishalmi
Copy link
Contributor Author

BTW. This PR marks all checks passed as it was missing the Platform label.

<change id="fileutil.niofilepath">
<api name="filesystems"/>
<summary>FileUtil can convert FileObject to/from java.nio.file.Path.</summary>
<version major="9" minor="30"/>
Copy link
Member

@sdedic sdedic Jan 13, 2023

Choose a reason for hiding this comment

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

9.32 (master has currently 9.31). We should probably bump version for each api change to allow proper autoupdates from the daily builds for those bleeding-edge testers.

* This is the inverse operation of {@link #toFileObject}.
* @param fo FileObject whose corresponding Path will be looked for
* @return java.nio.file.Path or null if no corresponding File exists.
* @since 9.30
Copy link
Member

Choose a reason for hiding this comment

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

9.31 if apichanges is corrected.

@@ -567,6 +569,7 @@ static FileObject copyFileImpl(FileObject source, FileObject destFolder, String
}

copy(bufIn, bufOut);
copyPosixPerms(source, dest);
Copy link
Member

Choose a reason for hiding this comment

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

Please make a mote in method's Javadoc about behaviour enhancement since 9.31(2), people can stop writing attribute preserving code, if they read javadoc :)

@lkishalmi lkishalmi merged commit b0d67bc into apache:master Jan 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform [ci] enable platform tests (platform/*)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants