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

[ISSUE] Files API mishandling valid dbfs paths #854

Open
reneket-nw opened this issue Jan 8, 2025 · 0 comments
Open

[ISSUE] Files API mishandling valid dbfs paths #854

reneket-nw opened this issue Jan 8, 2025 · 0 comments

Comments

@reneket-nw
Copy link

The SDK sniffs a requested path to convert a dbfs:/-style path to the canonical /-style path expected and returned by the API. A path that contains the string dbfs: is not reachable from the SDK; /dbfs: (an actual path that users have created) is sent as a request with the path /. As an added bonus, this leads to infinite recursion when listing / returns /dbfs: as one of the directories.

The relevant code is at _DbfsPath.__init__(), and there is similar code at _VolumesPath.__init__()

    def __init__(self, api: files.DbfsAPI, src: str):
        self._path = pathlib.PurePosixPath(str(src).replace('dbfs:', '').replace('file:', ''))
        self._api = api

This malforms the path if dbfs: or file: appears anywhere in the path other than the beginning. A possible solution might use re.sub() instead of str.replace() to assert the beginning of the path in the replacement search.

import re

FILESYSTEM_PREFIXES = r'^(dbfs|file):'

# ...

    def __init__(self, api: files.DbfsAPI, src: str):
        self._path = pathlib.PurePosixPath(re.sub(FILESYSTEM_PREFIXES, '', str(src)))
        self._api = api

Other Information

  • reported v0.40.0
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

No branches or pull requests

1 participant