Open
fix(e2b-scripts): 防止下载覆盖读取期间创建的本地文件 #284
fix(e2b-scripts): 防止下载覆盖读取期间创建的本地文件 #284
Open
任我飞Add on 1 day ago
任我飞
任我飞
1 day ago

问题与修复

运行 download-file 时,如果另一个进程在远端读取期间创建了本地目标文件,下载会静默覆盖该文件,即使用户没有指定 --overwrite。这违反了 e2b-scripts/README.md 中 DL-007 的覆盖保护约定。

保留下载前的存在性检查,并在最终打开目标文件时使用排他创建。若此时发生冲突,命令会提示目标已存在并保留对方写入的内容。显式指定 --overwrite 时仍按 DL-006 替换已有文件。

验证

使用真实临时目录和模拟 SDK,在远端读取回调中创建目标文件。原代码将该文件内容改写为下载数据,修复后拒绝覆盖。两项本地用例通过,同时覆盖二进制新建、已存在文件的提前拒绝和显式覆盖文本。未运行真实沙箱端到端测试。

AI 使用披露

本次使用 Codex 辅助定位、修复和验证。模型标识为 GPT-6,底层版本及接入方式未独立核实。任务为按下载命令的覆盖保护约定复现文件写入竞态,完成最小修复并验证。

likedislike
Merge blocked
任我飞任我飞
1 day ago Created pull request, commit 11585b67
atomgit-bot
atomgit-bot
1 day ago Comments:

变更摘要

本 PR 修复 e2b-scripts/e2b_validator/download_file.py 中 download_file 子命令的写入竞态问题:原先在远端读取前仅做一次存在性检查,随后直接用 write_bytes/write_text 覆盖写入,可能静默覆盖读取期间由其他进程创建的本地文件。修改后在最终打开目标文件时使用排他创建模式,将冲突转化为与前置检查一致的错误提示,同时保留显式 --overwrite 时的替换行为。

主要改动

  • 统一覆盖保护提示语: 在 execute 开头提取 exists_message 变量,前置存在性检查与写入阶段冲突共用同一提示文本,保持错误信息一致。
  • 写入方式改为排他创建: 以 mode = "w" if args.overwrite else "x" 决定打开模式,替换原来的 write_bytes/write_text,二进制内容使用 mode + "b" 并通过 local_path.open(...) 流式写入。
  • 捕获写入期文件冲突: 新增 except FileExistsError 分支,将其转换为 ValueError(exists_message),在冲突时提示目标已存在并保留对方写入的内容。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
1 day ago Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
openeuler-ci-botopeneuler-ci-botCollaborators
1 day ago Set weibaohui,yangzhao_kl,jimmieme,duguhaotian,wonleing,zmr_2020,gaodaweiky,lu-wei-army,feijianqiang,zhaoyifan28 as approver
openeuler-ci-botopeneuler-ci-botCollaborators
1 day ago Added label: sig/sig-CloudNative
openeuler-ci-bot
openeuler-ci-botCollaborators
1 day ago Comments:

Welcome To openEuler Community

Hey @renwofei423 , thanks for your contribution to the community.

Bot Usage Manual

I'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands. You can self-configure the PR merge rules for this repository. For more details, please refer to Here.

Contact Guide

If you have any questions, please contact the SIG: sig-CloudNative ,
and any of the maintainers: @duguhaotian, @feijianqiang, @gaodaweiky, @jimmieme, @lu-wei-army, @weibaohui, @wonleing, @yangzhao_kl, @zhaoyifan28, @zmr_2020 ,
and any of the committers: @feijianqiang, @fly_1997, @zhourenjianz .

likedislike
openeuler-ci-botopeneuler-ci-botCollaborators
1 day ago Added label: openeuler-cla/yes
openeuler-ci-bot
openeuler-ci-botCollaborators
1 day ago Comments:

CLA Signature Pass

renwofei423, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
openeuler-botopeneuler-botCollaborators
1 day ago Added label: ci_processing
openeuler-bot
openeuler-botCollaborators
1 day ago Comments:

门禁正在运行, 您可以通过以下链接查看实时门禁检查结果.
若您对门禁结果含义不清晰或者遇到问题不知如何解决,可参考门禁指导手册
门禁入口及编码规范检查: multiarch/openeuler/trigger/KASandbox/656

likedislike
openeuler-botopeneuler-botCollaborators
1 day ago Removed label: ci_processing
openeuler-bot
openeuler-botCollaborators
1 day ago Comments:
Check Name Build Result 详情 Build Details
check_package_license ✅SUCCESS #656
check_sca ✅SUCCESS
x86_64 check_build ✅SUCCESS #659
aarch64 check_build ✅SUCCESS #675
DT check_build ✅SUCCESS #672
check_interface check_build ✅SUCCESS #109
likedislike
openeuler-botopeneuler-botCollaborators
1 day ago Added label: ci_successful
openeuler-bot
openeuler-botCollaborators
1 day ago Comments:
likedislike