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

HPCC-30469 Avoid duplicated PathSepChar in getExternalPath() #17898

Merged
merged 1 commit into from
Oct 13, 2023

Conversation

wangkx
Copy link
Member

@wangkx wangkx commented Oct 12, 2023

Also add code to change the path to a relative path if needed.

Type of change:

  • This change is a bug fix (non-breaking change which fixes an issue).
  • This change is a new feature (non-breaking change which adds functionality).
  • This change improves the code (refactor or other change that does not change the functionality)
  • This change fixes warnings (the fix does not alter the functionality or the generated code)
  • This change is a breaking change (fix or feature that will cause existing behavior to change).
  • This change alters the query API (existing queries will have to be recompiled)

Checklist:

  • My code follows the code style of this project.
    • My code does not create any new warnings from compiler, build system, or lint.
  • The commit message is properly formatted and free of typos.
    • The commit message title makes sense in a changelog, by itself.
    • The commit is signed.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly, or...
    • I have created a JIRA ticket to update the documentation.
    • Any new interfaces or exported functions are appropriately commented.
  • I have read the CONTRIBUTORS document.
  • The change has been fully tested:
    • I have added tests to cover my changes.
    • All new and existing tests passed.
    • I have checked that this change does not introduce memory leaks.
    • I have used Valgrind or similar tools to check for potential issues.
  • I have given due consideration to all of the following potential concerns:
    • Scalability
    • Performance
    • Security
    • Thread-safety
    • Cloud-compatibility
    • Premature optimization
    • Existing deployed queries will not be broken
    • This change fixes the problem, not just the symptom
    • The target branch of this pull request is appropriate for such a change.
  • There are no similar instances of the same problem that should be addressed
    • I have addressed them here
    • I have raised JIRA issues to address them separately
  • This is a user interface / front-end modification
    • I have tested my changes in multiple modern browsers
    • The component(s) render as expected

Smoketest:

  • Send notifications about my Pull Request position in Smoketest queue.
  • Test my draft Pull Request.

Testing:

@wangkx wangkx requested review from jakesmith and ghalliday October 12, 2023 17:37
@github-actions
Copy link

@wangkx
Copy link
Member Author

wangkx commented Oct 12, 2023

A 9.0.x build has been tested.
Could the changes in the getExternalPath() cause any problem? Any better fix?

//If the prefix is a PathSepChar, it should not be appended to the dir here because
//a PathSepChar will be appended to the dir inside the expandExternalPath() if the s
//is started with the "::".
if (!streq(prefix, iswin ? "\\" : "/"))
Copy link
Member

Choose a reason for hiding this comment

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

if (!isRootDirectory(prefix))
is better, but will merge as-is

Copy link
Member

Choose a reason for hiding this comment

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

I don't think it's because it's "/" per se - I think it's problematic if there's a trailing '/' on the prefix.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I've tested, and if any plane prefix has a trailing '/', the result will be wrong, i.e. it will have a double // at the junction between the end of the prefix and the filePath portion.
So the fix here should be to check for trailing pathsepchar, and avoid appending it to 'dir', that will then also be correct for when prefix == "/"

Copy link
Member Author

Choose a reason for hiding this comment

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

Will change to isRootDirectory() and add the removeTrailingPathSepChar().

@@ -5642,6 +5642,24 @@ const char *splitRelativePath(const char *full,const char *basedir,StringBuffer
return t;
}

const char *getRelativePath(const char *path,const char *leadingPath)
Copy link
Member

Choose a reason for hiding this comment

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

note to myself - this is backported from 9.2

@@ -256,6 +256,16 @@ extern TPWRAPPER_API void validateDropZoneAccess(IEspContext& context, const cha
if (!isHostInPlane(dropZone, hostReq, true))
throw makeStringExceptionV(ECLWATCH_INVALID_INPUT, "Host %s is not valid DropZone plane %s", hostReq, targetDZNameOrHost);
}

//If the dropZonePath is an absolute path, change it to a relative path.
if (isAbsolutePath(fileNameWithRelPath))
Copy link
Member

Choose a reason for hiding this comment

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

can we also add some comment to CWsFileIOEx::onReadFileData in this PR (to reduce future confusion) to note that despite the "destRelativePath" saying it's relative for legacy reason, it also supports absolute paths?

(I'm also curious why ReadFileDataRequest uses fields with "Dest" in them, when this is only used for reading ..)

Copy link
Member Author

Choose a reason for hiding this comment

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

Will add the comment.
All of the three methods in WsFileIO uses the "Dest". But, it is not 'good' for the ReadFileDataRequest.

Copy link
Member

@jakesmith jakesmith left a comment

Choose a reason for hiding this comment

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

@wangkx - I think the fix will fix the issue if "/", but isn't quite right, see comment re. trailing pathSepChar

@wangkx wangkx requested a review from jakesmith October 13, 2023 12:52
//is started with the "::".
//Also a trailing pathsepchar in the prefix should be removed.
if (!isRootDirectory(prefix))
dir.append(prefix);
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you want or need to special case root, "/" is just an empty path with a trailing "/", so it will be covered by the next line afaics (comments should also change to reflect).

Copy link
Member Author

Choose a reason for hiding this comment

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

The removeTrailingPathSepChar() only removes the "/" if dir.length() > 1:

inline StringBuffer &removeTrailingPathSepChar(StringBuffer &path)
{
    if (path.length()>1 && isPathSepChar(path.charAt(path.length()-1)))
    {

Copy link
Member

Choose a reason for hiding this comment

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

ok

Copy link
Member

@jakesmith jakesmith left a comment

Choose a reason for hiding this comment

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

@wangkx - see comment

@wangkx wangkx requested a review from jakesmith October 13, 2023 13:03
Copy link
Member

@jakesmith jakesmith left a comment

Choose a reason for hiding this comment

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

@wangkx - please squash

Also add code to change the path to a relative path if needed.

Signed-off-by: wangkx <[email protected]>
Copy link
Member

@jakesmith jakesmith left a comment

Choose a reason for hiding this comment

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

@wangkx looks ok

@wangkx
Copy link
Member Author

wangkx commented Oct 13, 2023

@ghalliday this PR has been approved. You may merge it.

@wangkx
Copy link
Member Author

wangkx commented Oct 13, 2023

@ghalliday I noticed the test failure for workflow_9c.ecl. I just tested: 'ecl run roxie /home/lexis/src/HPCC-Platform/testing/regress/ecl/workflow_9c.ecl' in my local bare metal environment. No failure.

Copy link
Member

@jakesmith jakesmith left a comment

Choose a reason for hiding this comment

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

@wangkx - looks good.

@ghalliday ghalliday merged commit 34941fa into hpcc-systems:candidate-9.0.x Oct 13, 2023
46 of 49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants