Skip to content

fix: create sync downloads with the usual file permissions - #810

Merged
ffumero2003 merged 1 commit into
masterfrom
fix-sync-issue-809-download-file-mode
Dec 1, 2026
Merged

ffumero2003 merged 1 commit into
masterfrom
fix-sync-issue-809-download-file-mode

Conversation

@ffumero2003

Copy link
Copy Markdown
Contributor

Context

Since #807, a sync download on POSIX creates its temporary file through a directory descriptor with open(name, 'xb+', opener=functools.partial(os.open, dir_fd=directory_fd)). open() calls an opener without a mode, so os.open defaults to 0o777. The file gets the execute bits (0o777 & ~umask), and os.replace keeps them, so every downloaded file ends up executable (0o755 under umask 022, where 2.13.5 produced 0o644).

Root cause

The opener omitted the file mode. Plain open() uses 0o666; a custom opener has to pass it explicitly.

Changes

  • b2sdk/_internal/sync/action.py: pass mode=0o666 in the opener, so the umask yields the same permissions as before.
  • test/unit/sync/test_regression_sync_actions.py: add test_download_file_mode_follows_umask, parametrized over the descriptor-pinned path and the pathname fallback, asserting 0o644 under umask 022.
  • changelog.d/809.fixed.md.

Verification

  • The new test is red before the fix on the pinned path (0o755 instead of 0o644) and green after. Removing the mode argument fails only the pinned case; the pathname fallback was already correct.
  • ruff format and check pass on b2sdk and test.
  • Unit suites pass on all four API versions: v0 1523, v1 1684, v2 1684, v3 1715 passed.
  • Not run: live B2, Windows (the test is skipped there; Windows does not use the descriptor path).

Closes #809

An opener passed to open() is called without a mode, so os.open defaulted to 0o777 and downloaded files became executable. Pass 0o666 so the umask yields the same mode as before.
@ffumero2003 ffumero2003 self-assigned this Dec 1, 2026
@ffumero2003
ffumero2003 requested a review from goanpeca December 1, 2026 18:46
@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The download action now passes mode 0o666 when it opens a temporary file. A POSIX-only regression test checks file contents and mode 0o644 with umask 0o022 for pinned and unpinned destination paths. The changelog records the permission behavior.

Merge Risk: Minimal · up to 24272

Sync downloads on POSIX will get the usual umask-filtered permissions instead of being made executable. The change is one opener argument plus a regression test and a changelog entry, and no merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: sync downloads get the usual file permissions on POSIX. It matches the changeset, which passes mode=0o666 to the opener so that downloads are no longer executable. The…
Description check Passed The description explains the cause (the custom opener omits the mode, so os.open defaults to 0o777), the fix (mode=0o666 in action.py), the new regression test, the changelog fragment, and the verific…
Linked Issues check Passed [#809] requires POSIX sync downloads to create files with mode 0o666 & ~umask on both the descriptor-pinned path and the pathname fallback. At the reviewed head, B2DownloadAction.do_action in b2sdk/_i…
Out of Scope Changes check Passed The changes are the one-argument opener fix in B2DownloadAction.do_action, a regression test in test/unit/sync/test_regression_sync_actions.py for that behavior, and a towncrier fragment changelog.d/8…
Full details: Title check

Explanation

The title names the main change: sync downloads get the usual file permissions on POSIX. It matches the changeset, which passes mode=0o666 to the opener so that downloads are no longer executable. The title is specific and uses the fix: prefix.

Full details: Description check

Explanation

The description explains the cause (the custom opener omits the mode, so os.open defaults to 0o777), the fix (mode=0o666 in action.py), the new regression test, the changelog fragment, and the verification steps. It is directly related to the changeset.

Full details: Linked Issues check

Explanation

[#809] requires POSIX sync downloads to create files with mode 0o666 & ~umask on both the descriptor-pinned path and the pathname fallback. At the reviewed head, B2DownloadAction.do_action in b2sdk/_internal/sync/action.py builds the opener as functools.partial(os.open, mode=0o666, dir_fd=directory_fd) for the pinned path. The fallback uses open(download_path, 'xb+') with no opener, so it already applies 0o666 & ~umask. The fix is one argument in the opener, which matches the issue's scope. The PR summary and description state that test_download_file_mode_follows_umask is parametrized over both paths, asserts 0o644 under umask 022, and fails before the fix on the pinned path. The changelog fragment changelog.d/809.fixed.md is present. Limitation: the test file diff could not be read (changed blobs unavailable in checkout), so the test content is established from the PR summary and description, not from source. Remaining check-to-syscall race (#807) and policy question (#808) are excluded by the issue and are not required here.

Full details: Out of Scope Changes check

Explanation

The changes are the one-argument opener fix in B2DownloadAction.do_action, a regression test in test/unit/sync/test_regression_sync_actions.py for that behavior, and a towncrier fragment changelog.d/809.fixed.md. Each change connects directly to #809's acceptance criteria. The code at the reviewed head shows no other behavior change in the download path. The test file diff could not be read directly, so the absence of unrelated edits in that file rests on the PR summary, which lists only the added test and the stat import.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: da5256ff-8d7c-4a97-bc79-1f0eec90ff87
Commits

Reviewing files that changed from the base of the PR and between abcf08c and 242726c.

Files selected for processing: 3

  • b2sdk/_internal/sync/action.py
  • changelog.d/809.fixed.md
  • test/unit/sync/test_regression_sync_actions.py

Included review availability: This review used your included allowance. Your plan provides up to 5 included reviews per hour; 1 remain after this review.

@ffumero2003
ffumero2003 merged commit de4bb93 into master Dec 1, 2026
31 checks passed
@ffumero2003
ffumero2003 deleted the fix-sync-issue-809-download-file-mode branch December 1, 2026 18:50
@ffumero2003 ffumero2003 mentioned this pull request Dec 1, 2026
3 tasks
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.

fix: sync downloads create executable files on POSIX

1 participant