Skip to content

Local storage downloads onto the source delete the stored object #2200

Open

Description

@zhechen-cs

Summary

LocalStorageDriver.download_object() deletes the stored object when the destination resolves to the source file and overwrite_existing=True is used. The default failure cleanup unlinks the source after shutil.copy() raises SameFileError.

Reproducer

On current trunk (bd9cbb3e393bc42f57684481e7c62e9293007584), Python 3.12:

import os
import tempfile
from libcloud.storage.drivers.local import LocalStorageDriver

with tempfile.TemporaryDirectory() as root:
    driver = LocalStorageDriver(root)
    container = driver.create_container("bucket")
    obj = driver.upload_object_via_stream(iter([b"payload"]), container, "object")
    path = os.path.join(root, "bucket", "object")
    print(driver.download_object(obj, path, overwrite_existing=True))  # False
    print(os.path.exists(path))  # False: the stored object was deleted

The failed download should preserve the source. The same deletion occurs when the destination is the containing directory with a trailing path separator.

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