Skip to content

Sync download deletes the old local file before renaming the new one into place #655

Open

Description

@sophiecarreras

What happens

After downloading to the .b2.sync.tmp file, the sync download action calls os.unlink on the existing local file and then os.rename. If the rename fails, the previous local copy is already gone. os.replace would swap the file in one step.

Where

b2sdk/_internal/sync/action.py:331-334 (B2DownloadAction.do_action, os.unlink at :333 and os.rename at :334).

Why it matters

Impact: Data, loud (the rename raises OSError). Severity: Low, because it needs a rename that fails after the unlink, and the downloaded data stays in the temporary file while the remote copy is intact.

How to check

Read the lines above; to see it, make os.rename raise (for example by a permission error on the target directory entry) and note the old file is missing. Found by reading the code, not reproduced.

Version

Seen at v2.13.4. Present on the default branch: present.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions