shutil.copy2 does not copy sparse files efficiently
未关闭
还没有人认领这个 Issue。
type-feature
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
Bug description:
$ dd if=/dev/zero of=sparse_original bs=1 count=1 oseek=1M
1+0 records in
1+0 records out
1 byte copied, 2.7367e-05 s, 36.5 kB/s
$ cp sparse_original sparse_cp
$ python3 -c 'import shutil; shutil.copy2("sparse_original", "sparse_pycopy2");'
$ du sparse_original sparse_cp sparse_pycopy2
4 sparse_original
4 sparse_cp
1028 sparse_pycopy2
Ideally shutil.copy2() should be capable of copying sparse files without unnecessarily expanding them (this is the default behavior of cp).
This could potentially be implemented using lseek(2) SEEK_DATA and SEEK_HOLE.
CPython versions tested on:
3.12
Operating systems tested on:
Linux
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 shutil.copy2 入口点开始,在 Linux 上复现稀疏文件示例。研究使用 SEEK_DATA 和 SEEK_HOLE 的 lseek(2),然后验证复制的文件是否像 cp 一样保留空洞,而不是将其扩展。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- linux, python
- 领域
- operating-systems
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 38/100