You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Use handle-based exclusive creation in FileHelper - #5354
Use handle-based parent traversal for FileHelper.create_bytes() and create_text(), so exclusive creation uses the policy-resolved directory throughout the operation.
POSIX creation opens resolved parents without following new links and creates the file relative to the final directory descriptor. Windows creation pins the resolved hierarchy using the existing handle primitive, extracted into a shared private module.
Preserves supported contained parent links and link chains, trusted root aliases, deny-mode rejection, existing-leaf rejection, existing-parent requirements, mode/umask semantics, and byte/text encoding behavior. Adds focused creation coverage and updates the filesystem contract. Read, deletion, and overwrite behavior are unchanged.
Testing
Set up this checkout's .venv and editable install using the local development guide. Run commands from the checkout root.
Tested locally with .venv/bin/specify --help (Windows PowerShell: .\.venv\Scripts\specify.exe --help)
Ran relevant existing tests with .venv/bin/python -m pytest tests -q (Windows PowerShell: .\.venv\Scripts\python.exe -m pytest tests -q); use affected test paths for focused checks and LC_ALL=en_US.UTF-8 on macOS
Validation ran on macOS. Native Windows tests are included but were not executed on this host. A separate sample-project run was not performed; the affected filesystem operations are exercised directly by the focused tests.
AI Disclosure
I did not use AI assistance for this contribution
I did use AI assistance (fill in the disclosure below)
AI disclosure: Implemented with GitHub Copilot using GPT-6.1 Sol (model ID: gpt-6.1-sol) in autopilot/autonomous mode. AI assistance covered implementation, tests, documentation, validation execution, and this PR description on behalf of @mnriem.
Anchor byte and text creation to policy-resolved parent directories while preserving contained links, root aliases, modes, and encoding. Reuse the Windows handle primitive and cover creation behavior with focused tests.
Assisted-by: GitHub Copilot (model: gpt-6.1-sol, autonomous)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The extracted CreateFileW prototype omits a required DWORD argument, causing TypeError failures in Windows exclusive creation and workflow/step catalog cache access.
Restore the complete CreateFileW prototype, use search-only POSIX directory handles where available, and close previous parent descriptors during traversal. Add regression coverage for the Windows prototype, directory permissions, and bounded descriptor use.
Assisted-by: GitHub Copilot (model: gpt-6.1-sol, autonomous)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Use Darwin's native O_SEARCH value when Python does not expose the flag. Cover write/search-only parents with missing exported search flags and preserve no-follow directory traversal.
Assisted-by: GitHub Copilot (model: gpt-6.1-sol, autonomous)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The exclusive-creation fallback requires directory read permission when search-only flags are unavailable, breaking supported write-and-traverse-only cases and their existing permission tests.
Clarify race disclaimer covers all path-based operations
design/file-helper.md:223
“Those path-based operations” can be read as limiting the race disclaimer to writes and deletion. Reads, overwrite_text, and symlink creation still use validated paths that can be redirected by a concurrent parent swap. Keep the disclaimer covering all path-based operations, except for the exclusive-creation parent anchoring described below.
Document Windows directory-listing and attribute access for pinned parents, and keep the path-based-operation disclaimer explicit for reads, directory creation, writes, overwrites, symlink creation, and deletion.
Assisted-by: GitHub Copilot (model: gpt-6.1-sol, autonomous)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Addressed the review feedback in e506d29, 6083180, and 95e7a69: restored the complete Windows CreateFileW prototype, bounded POSIX directory-descriptor use, preserved write/search-only access on older macOS Python builds, documented Windows directory-listing and attribute-access requirements, and clarified the limits for all remaining path-based operations. The latest head is 95e7a69. Local focused checks passed (530 tests, 92 skipped), the affected workflow/catalog checks passed (1,960 tests, 29 skipped), and Ruff and whitespace checks passed. Upstream CI on 95e7a69 passed all nine Linux/macOS/Windows Python jobs, including native Windows tests and macOS Python 3.11, and the lint/dependency-audit check passed. On behalf of @mnriem: this response and the changes were generated with GitHub Copilot using GPT-6.1 Sol (gpt-6.1-sol) in autopilot/autonomous mode, covering implementation, tests, documentation, validation execution, and review-response text.
Full-path creation follows a parent changed to a junction
src/specify_cli/file_helper.py:223
On Windows, an empty pinned parent can still be converted in place into a junction: FSCTL_SET_REPARSE_POINT accepts FILE_WRITE_ATTRIBUTES, which withholding delete sharing does not block. If this happens after the handle's attribute check, this full-path open follows the junction and creates the file outside the root. Use handle-relative creation with reparse refusal, and add a native Windows regression that converts the empty parent immediately before creation.
Reusing this handle for FileHelper.create_*() adds a Windows permission requirement: 0x1 is FILE_LIST_DIRECTORY. A non-privileged user can have traversal and file-creation rights without directory-listing rights; the previous exclusive os.open() could create there, but this parent handle now fails with access denied. Use pinning access rights that do not require listing while still enforcing delete-sharing checks, and add a native Windows ACL regression case.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You can’t perform that action at this time.
✕
Wait! Don't Go Yet 🚀
Get our FREE eBook "10 Programming Tips That Changed Everything" when you subscribe!
Description
Use handle-based parent traversal for
FileHelper.create_bytes()andcreate_text(), so exclusive creation uses the policy-resolved directory throughout the operation.POSIX creation opens resolved parents without following new links and creates the file relative to the final directory descriptor. Windows creation pins the resolved hierarchy using the existing handle primitive, extracted into a shared private module.
Preserves supported contained parent links and link chains, trusted root aliases, deny-mode rejection, existing-leaf rejection, existing-parent requirements, mode/umask semantics, and byte/text encoding behavior. Adds focused creation coverage and updates the filesystem contract. Read, deletion, and overwrite behavior are unchanged.
Testing
Set up this checkout's
.venvand editable install using the local development guide. Run commands from the checkout root..venv/bin/specify --help(Windows PowerShell:.\.venv\Scripts\specify.exe --help).venv/bin/python -m pytest tests -q(Windows PowerShell:.\.venv\Scripts\python.exe -m pytest tests -q); use affected test paths for focused checks andLC_ALL=en_US.UTF-8on macOSCommands and results:
.venv/bin/specify --help— passed.LC_ALL=en_US.UTF-8 .venv/bin/python -m pytest tests/test_file_helper.py tests/specify_cli/workflows/test_catalog_cache.py tests/specify_cli/test_file_policy.py -q— 476 passed, 92 skipped.git diff --check— passed.Validation ran on macOS. Native Windows tests are included but were not executed on this host. A separate sample-project run was not performed; the affected filesystem operations are exercised directly by the focused tests.
AI Disclosure
AI disclosure: Implemented with GitHub Copilot using GPT-6.1 Sol (model ID:
gpt-6.1-sol) in autopilot/autonomous mode. AI assistance covered implementation, tests, documentation, validation execution, and this PR description on behalf of @mnriem.