-
Notifications
You must be signed in to change notification settings - Fork 588
HDDS-13444. Unify isValidKeyPath implementation #9521
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?
Conversation
echonesis
left a comment
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.
Thanks @rich7420 , left some comments.
| if (allowLeadingSlash && i == 0) { | ||
| // Allow empty at start for absolute paths | ||
| continue; | ||
| } |
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.
It seems this section is not included in original OMClientRequest.isValidKeyPath().
Please describe more details in the commit message section.
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.
sure!
| * Add reference counter to an object instance. | ||
| */ | ||
| class ReferenceCounted<T> { | ||
| public class ReferenceCounted<T> { |
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.
Could we keep it package-private?
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 change to public cuz ci test error. I'll try to figure out the solution to keep it private.
| * Whether the pathname is valid. Currently prohibits relative paths, | ||
| * names which contain a ":" or "//", or other non-canonical paths. | ||
| */ | ||
| public static boolean isValidName(String src) { |
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.
nit: use path instead of src to keep it consistent with isValidKeyPath
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.
sure, thanks for the reminder!
| } | ||
|
|
||
| @Test | ||
| public void testIsValidKeyPath() throws OMException { |
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.
We could add some tests like
assertEquals("a/b/", OzoneFSUtils.isValidKeyPath("a/b/", true));assertThrows(OMException.class, () -> OzoneFSUtils.isValidKeyPath("/a/b", false));
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.
no problem!
sreejasahithi
left a comment
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.
Thanks @rich7420 for working on this, left few comments
| public static String isValidKeyPath(String path, boolean throwOnEmpty) throws OMException { | ||
| if (path.isEmpty()) { | ||
| if (throwOnEmpty) { | ||
| throw new OMException("Invalid KeyPath, empty keyName" + path, |
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.
| throw new OMException("Invalid KeyPath, empty keyName" + path, | |
| throw new OMException("Invalid KeyPath, empty keyName " + path, |
or we could instead remove path from the message as it is empty and the message already says empty KeyName.
| } | ||
|
|
||
| @Test | ||
| public void testIsValidKeyPath() throws OMException { |
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.
you can add some more test cases for key paths likefile.txt, ./file
What changes were proposed in this pull request?
This PR unified the duplicated isValidKeyPath validation logic between OzoneFSUtils and OMClientRequest by extracting the common path validation into a shared private method validateKeyPathComponents, and made OMClientRequest.isValidKeyPath delegate to OzoneFSUtils.isValidKeyPath to remove code duplication.
What is the link to the Apache JIRA
HDDS-13444
How was this patch tested?
https://github.com/rich7420/ozone/actions/runs/20323872107