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

Improve Javadoc of ConfigurableFilePermissions.html#unix(int) #30369

Closed
sdavids opened this issue Aug 31, 2024 · 7 comments
Closed

Improve Javadoc of ConfigurableFilePermissions.html#unix(int) #30369

sdavids opened this issue Aug 31, 2024 · 7 comments

Comments

@sdavids
Copy link
Contributor

sdavids commented Aug 31, 2024

Expected Behavior

Prevent misuse of API.

It is easy to think that unix(755) is rwxr-xr-x.


https://docs.gradle.org/current/javadoc/org/gradle/api/file/ConfigurableFilePermissions.html#unix(int)

Sets Unix style numeric permissions. See unix(String) for details.

https://docs.gradle.org/current/javadoc/org/gradle/api/file/ConfigurableFilePermissions.html#unix(java.lang.String)

The NUMERIC notation consist of 3 digits having values from 0 to 7. 1st digit represents the OWNER, 2nd represents the GROUP while the 3rd represents OTHER users.

Examples:

Numeric Symbolic Meaning
000 --------- no permissions
700 rwx------ read, write & execute only for owner

The description and the table suggest using a 3-digit number.

Current Behavior

public void unix(int unixNumeric) {
user.unix(getUserPartOf(unixNumeric));
group.unix(getGroupPartOf(unixNumeric));
other.unix(getOtherPartOf(unixNumeric));
}

protected static int getUserPartOf(int unixNumeric) {
return (unixNumeric & 0_700) >> 6;
}

public void unix(int unixNumeric) {
setRead(isRead(unixNumeric));
setWrite(isWrite(unixNumeric));
setExecute(isExecute(unixNumeric));
}

protected static boolean isRead(int unixNumeric) {
return (unixNumeric & 4) >> 2 == 1;
}

jshell --feedback=silent - <<< 'System.out.println((((755 & 0_700) >> 6) & 4) >> 2 == 1)'
false
 ~ % jshell --feedback=silent - <<< 'System.out.println((((0755 & 0_700) >> 6) & 4) >> 2 == 1)'
true

Context

https://docs.gradle.org/current/userguide/working_with_files.html#sec:setting_file_permissions

file: read & write for owner, read for group, read for other (0644, rw-r—​r--)

directory: read, write & execute for owner, read & execute for group, read & execute for other (0755, rwxr-xr-x)

https://docs.gradle.org/current/javadoc/org/gradle/api/file/FilePermissions.html

FILE: read & write for OWNER, read for GROUP, read for OTHER (0644, rw-r--r--)
DIRECTORY: read, write & execute for OWNER, read & execute for GROUP, read & execute for OTHER (0755, rwxr-xr-x)

Both are OK but could be improved with a WARNING that if using a number it should be in octal format.


unix(755) // not what one expects
unix(0755)
unix("755")
unix("rwxr-xr-x")
@sdavids
Copy link
Contributor Author

sdavids commented Aug 31, 2024

https://kotlinlang.org/docs/numbers.html#literal-constants-for-numbers

Octal literals are not supported in Kotlin.

With the Gradle Kotlin-DSL unix(int) is basically useless and/or always leads to not what one expects.

@sdavids
Copy link
Contributor Author

sdavids commented Aug 31, 2024

Maybe deprecate unix(int)?

sdavids added a commit to sdavids/adr-j that referenced this issue Sep 1, 2024
@ljacomet
Copy link
Member

ljacomet commented Sep 3, 2024

This issue needs a decision from the team responsible for that area. They have been informed. Response time may vary.


At the minimum, the introduced unix(int) should have javadoc calling out this behaviour.

But we should consider if that method is really needed.

Copy link
Contributor

@jbartok This issue was closed as completed and looks release-note worthy, but no PR with release-notes update has been found.
Please, do one of the following:

  1. Attach a PR with the release notes update to this issue.
  2. Add the has:release-notes-decision label to the issue if it's not release-note-worthy or it was fixed in an old release and close the issue.
  3. Close issue as "not planned".

@github-actions github-actions bot added the pending:release-notes Indicates that the issue requires a release notes entry label Sep 16, 2024
@ov7a ov7a added this to the 8.11 RC1 milestone Sep 30, 2024
@jbartok jbartok closed this as completed Oct 2, 2024
@github-actions github-actions bot reopened this Oct 2, 2024
Copy link
Contributor

github-actions bot commented Oct 2, 2024

@jbartok This issue was closed as completed and looks release-note worthy, but no PR with release-notes update has been found.
Please, do one of the following:

  1. Attach a PR with the release notes update to this issue.
  2. Add the has:release-notes-decision label to the issue if it's not release-note-worthy or it was fixed in an old release and close the issue.
  3. Close issue as "not planned".

@jbartok jbartok added has:release-notes-decision and removed 👋 team-triage Issues that need to be triaged by a specific team labels Oct 2, 2024
@jbartok
Copy link
Member

jbartok commented Oct 2, 2024

The change is not release notes worthy (in my opinion).

@jbartok jbartok closed this as completed Oct 2, 2024
@github-actions github-actions bot removed the pending:release-notes Indicates that the issue requires a release notes entry label Oct 2, 2024
@jbartok
Copy link
Member

jbartok commented Oct 2, 2024

A couple of comments about the PR based on which this issue has been closed.

First of all, the problem/concern is not entirely realistic. Anybody who has to deal with UNIX style file permissions should be aware, to some extent at least, of the fact that the int value only makes sense in octal. So we have decided not to completely remove the method.

But, there is indeed some room for improvement, and that's what we did:

  • we added validation which should catch many of the completely nonsensical inputs, that can be accidentally used
  • we improved the JavaDoc to make the meaning of the values even clearer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants