Skip to content

fix: strip trailing separator in FileSystem.is_writeable - #4300

Merged
epatey merged 3 commits into
UKGovernmentBEIS:mainfrom
he-yufeng:fix/is-writeable-trailing-sep
Jun 23, 2026
Merged

epatey merged 3 commits into
UKGovernmentBEIS:mainfrom
he-yufeng:fix/is-writeable-trailing-sep

Conversation

@he-yufeng

Copy link
Copy Markdown
Contributor

Summary

FileSystem.is_writeable() calls path.rstrip("/\\") but discards the result, so the trailing separator is never actually stripped:

touch_filename = _WRITE_TEST_FILENAME if is_azure_path(path) else uuid()
path.rstrip("/\\")                                  # no-op: result discarded
touch_file = f"{path}{self.fs.sep}{touch_filename}"

FileRecorder.is_writeable() passes the user's log_dir straight through, and log dirs are commonly given with a trailing slash (--log-dir ./logs/, s3://bucket/logs/). With the trailing slash left in place, the write-test path becomes s3://bucket/logs//.inspect_write_test — a double separator, which is a malformed key on S3/Azure.

Fix

Assign the stripped value back:

path = path.rstrip("/\\")

(The module already has a strip_trailing_sep() helper; this just makes the existing inline strip actually take effect.)

Test

Added test_is_writeable_strips_trailing_sep in tests/util/test_file.py: it calls is_writeable("mydir/") on an in-memory filesystem (with touch/rm patched) and asserts the write-test path contains no double separator. It fails on main (assert '//' not in 'mydir//...') and passes with this change.

Verified locally with pytest tests/util/test_file.py::test_is_writeable_strips_trailing_sep and ruff check / ruff format --check (clean). A few unrelated path/URI tests in that file fail only on a Windows checkout due to POSIX-path assumptions; they're untouched by this change and pass on CI.

@he-yufeng
he-yufeng force-pushed the fix/is-writeable-trailing-sep branch 2 times, most recently from ea2368f to af28722 Compare June 21, 2026 16:53
@he-yufeng
he-yufeng force-pushed the fix/is-writeable-trailing-sep branch from af28722 to e9e4d81 Compare June 22, 2026 19:46
@he-yufeng
he-yufeng force-pushed the fix/is-writeable-trailing-sep branch from e9e4d81 to 61fc0c5 Compare June 22, 2026 22:52

@epatey epatey left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the change.

@epatey
epatey merged commit 7493435 into UKGovernmentBEIS:main Jun 23, 2026
15 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.

2 participants