Skip to content

Fix user context for streamed MLSD and MLST metadata - #698

Open
manav4u wants to merge 1 commit into
giampaolo:masterfrom
manav4u:fix-mlsx-user-context-593
Open

manav4u wants to merge 1 commit into
giampaolo:masterfrom
manav4u:fix-mlsx-user-context-593

Conversation

@manav4u

@manav4u manav4u commented Nov 25, 2026

Copy link
Copy Markdown

Fixes #593.

format_mlsx is lazy, so entering the user context only when creating its iterator leaves the later metadata reads outside that context. This breaks custom filesystems that need the FTP user's credentials for stat.

For MLST, consume the iterator inside run_as_current_user. For MLSD, create the iterator and read each existing 20-entry producer buffer in that context, restoring it before returning to the event loop. Listings remain streamed; this does not hold impersonation across yields to the event loop or change LIST/STAT behavior.

The regressions cover a custom authorizer/filesystem over real FTP for MLST and a 45-entry, multi-buffer MLSD listing, plus producer context restoration on exhaustion, errors and early iterator close. Both functional regressions fail against unchanged source.

Local validation on Linux, against unchanged upstream b657392:

  • Python 3.8, 3.10 and 3.14: 661 passed, 53 skipped each. Python 3.14 reports 124 existing fork-deprecation warnings; 3.8 reports 15 pytest configuration warnings.
  • Changed-code Ruff/Black and git diff --check pass.
  • A final docstring-only change was followed by the three targeted tests passing on 3.14. The full suites above were run before that docstring change, not rerun for publication.

The tests use custom authorizer hooks, not real Unix UID/GID changes or Windows tokens. No Windows/macOS or full hosted matrix result is claimed.

AI-assisted implementation and local validation.

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.

format_mlsx not within "run_as_current_user"

1 participant