Local range download leaves an output file after source-read failure despite delete_on_failure=True

未關閉 適合新手
#2,223 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
82/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python
領域
cloud

研究方向

閱讀 libcloud/storage/base.py 中的範圍下載契約,以及 libcloud/storage/drivers/local.py 中的本機實作。重現 issue 中來源缺失的情況,然後在本機驅動程式現有測試旁新增一個迴歸測試。當範圍下載失敗且 delete_on_failure=True 時會刪除目的地,同時旗標為 false 時的行為仍符合預期,即表示完成。

由索引模型根據 Issue 內容生成。

描述

On trunk 8a0ef626, the local driver's range-download method creates a destination file but does not clean it up when opening the source fails, even with delete_on_failure=True.

This reproducer is sequential: obtain the object metadata, explicitly remove the stored file, then try to download. It does not depend on winning a filesystem race.

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")
    os.unlink(driver.get_object_cdn_url(obj))
    destination = os.path.join(root, "download")
    try:
        driver.download_object_range(
            obj, destination, start_bytes=0, delete_on_failure=True
        )
    except FileNotFoundError:
        pass
    print(os.path.exists(destination), os.path.getsize(destination))
    # True 0

The public range-download contract describes delete_on_failure as deleting a partially downloaded file when the download was unsuccessful, with hash mismatch/file size given as examples. I expected the newly created empty output to be removed for a source-read failure as well. Otherwise a failed operation leaves a file that can be mistaken for a valid empty download.

The local implementation accepts the flag but never reads it. It opens the destination before consuming the source iterator and has no failure cleanup around that loop.

Checks with unchanged source, Python 3.12/Linux:

  • Range download with delete_on_failure=True: raises FileNotFoundError, leaves a zero-byte output.
  • Range download with delete_on_failure=False: same result.
  • Full download_object with the same missing source: returns False, leaves no output.
  • Successful range [0, 3) before removing the source: returns True, writes b"pay".

No code change yet. This report is limited to failure cleanup for local range downloads; it does not claim a concurrent-write reproduction or a full test-suite pass.

主要語言
Python
星號
2.1k
分支
935
平均合併
5 天 3 小時
30 天內合併 PR
15

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

apache/libcloud 的其他 Issue

查看 apache/libcloud 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。