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

Fixed pathlib bug for Windows by change to PurePosixPath #145

Merged
merged 2 commits into from
Apr 1, 2025

Conversation

lshaw8317
Copy link
Collaborator

@lshaw8317 lshaw8317 commented Mar 31, 2025

Reproduce error:
import caterva2
public = caterva2.Root('@public', urlbase="https://cat2.cloud/demo")
print(public['examples/dir1/ds-2d.b2nd'])

Tries to request https://cat2.cloud/demo/api/info/@public\examples\dir1\ds-2d.b2nd (i.e with backslashes) and fails due to Windows file path convention. Fixed by forcing Unix-type (Posix) filepath naming.

@FrancescAlted
Copy link
Member

Ok. Now we have this issue:

        if path is not None:
            p = path.as_posix() if isinstance(path, pathlib.Path) else path
>           if p.startswith("/"):
E           AttributeError: 'PurePosixPath' object has no attribute 'startswith'

Can you replace the code above by:

# Ensure path is a string before checking startswith
p = path.as_posix() if hasattr(path, "as_posix") else str(path)
if p.startswith("/"):

and see how it goes?

@lshaw8317
Copy link
Collaborator Author

Running on windows with following script
´´
import caterva2
public = caterva2.Root('@public', urlbase="https://cat2.cloud/demo")
print(public['examples/dir1/ds-2d.b2nd'])
``
incorrectly generated path and failed to find the server-hosted file. With bug fix suggested in commit, script now runs without error.

@FrancescAlted
Copy link
Member

Looks good to me. Thanks @lshaw8317 !

@FrancescAlted FrancescAlted merged commit a1d3625 into ironArray:main Apr 1, 2025
3 checks passed
lshaw8317 added a commit to lshaw8317/Caterva2 that referenced this pull request Apr 2, 2025
Merge pull request ironArray#145 from lshaw8317/bugFixer
lshaw8317 added a commit to lshaw8317/Caterva2 that referenced this pull request Apr 2, 2025
Merge pull request ironArray#145 from lshaw8317/bugFixer
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.

2 participants