Skip to content

Fixed BucketPath using backslash separators on Windows - #325

Open
Ramnath0521 wants to merge 1 commit into
exasol:mainfrom
Ramnath0521:fix/issue-322
Open

Ramnath0521 wants to merge 1 commit into
exasol:mainfrom
Ramnath0521:fix/issue-322

Conversation

@Ramnath0521

Copy link
Copy Markdown

Closes #322

Cause

BucketPath stored its path as PurePath(path), which is a PureWindowsPath on Windows. Only _get_relative_posix() converted it back to forward slashes. read(), write(), rm(), __str__, iterdir() and as_udf_path() used str(self._path) directly and so sent backslash paths to BucketFS, as described in the issue.

Change

Following the suggestion in the issue, BucketPath now stores a PurePosixPath:

  • __init__ builds a PurePosixPath. A PurePath argument (for example a PureWindowsPath or WindowsPath) is converted with as_posix() first, so joinpath() with Windows path objects also works.
  • _get_relative_posix() no longer needs its PureWindowsPath special case.
  • as_udf_path() builds the result with PurePosixPath, so the UDF path uses / on every platform.

Behaviour on Linux and macOS is unchanged, because PurePath is already PurePosixPath there.

Two things on Windows are different now and worth a look:

  • A plain string containing a backslash is no longer split into path parts; paths in a bucket are POSIX paths. PureWindowsPath/WindowsPath objects are still accepted and converted.
  • relative_to() returns a PurePosixPath instead of a PureWindowsPath. I updated the one existing assertion that compared against PurePath(...) accordingly.

Tests

New test/unit/test_bucket_path_separators.py (7 tests) uses a recording fake bucket API and PureWindowsPath inputs, so it runs the same on every OS and does not need to patch PurePath the way the issue's Linux emulation does. It covers str(), write()/read()/rm(), joinpath(), iterdir() and as_udf_path().

On the unfixed code (Windows 11, Python 3.12) 5 of the new tests fail, with the backslash paths from the issue ('dir\sub\a.txt' == 'dir/sub/a.txt'); with the fix all 7 pass.

I also ran the whole test/unit folder on Windows. It does not pass on Windows even before this change (17 failures). With this change it is 14 failures, none new, and test_joinpath, test_truediv and test_archive_as_udf_path now pass. The remaining 14 come from the bucket_fake fixture: MountedBucket.files on a local directory returns backslash paths on Windows. I left that out because it is a separate code path (a locally mounted bucket) from the one in this issue, but I'm happy to look at it in a follow-up if you want it.

black --check, isort --check and mypy are clean on the changed files. I did not run the integration tests or the full nox sessions.

Checklist

  • Mentioned the issue this closes
  • Updated the changelog in doc/changes/unreleased.md

Written with AI assistance (Claude Code). I reproduced the failure on my own Windows machine, read the fix, and verified the added tests fail before it and pass after. Errors are mine.

🤖 Generated with Claude Code

BucketPath stored its path as PurePath, which is a PureWindowsPath on
Windows, so read(), write(), rm(), iterdir() and as_udf_path() sent
backslash paths to BucketFS. Store a PurePosixPath instead, converting
PurePath arguments with as_posix().

Closes exasol#322

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

This branch has not been deployed

No deployments
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.

BucketPath uses backslash separators on Windows

1 participant