resize --output . silently overwrites and destroys the source image
还没有人认领这个 Issue。
评估
调研方向
从 ipro resize 入口开始,使用 orig.jpg --width 400 --output . 重现冲突。跟踪写入前输入路径和输出路径的解析过程;完成标准是:除非实现了文档中说明的强制行为,否则对于相同的已解析路径应以明确的错误拒绝,同时源文件保持不变。
由索引模型根据 Issue 内容生成。
描述
ipro resize writes its output using the same basename as the input and relies
on the output directory to keep the two apart. When --output points at the
directory the source already lives in, the resized file lands on top of the
original and destroys it. There is no warning, no prompt, and no error. The
success line even reports the overwritten path as if it were a new file.
The original is unrecoverable.
Reproduction
ipro-cli 1.6.0, Python 3.14.3, macOS 26.6.
$ magick -size 2000x1000 gradient:navy-orange orig.jpg
$ magick identify -format '%wx%h %[size]' orig.jpg
2000x1000 75631B
$ ipro resize orig.jpg --width 400 --output .
✓ Created: orig.jpg (400x200, 3 KB)
Successfully created 1 image(s) from orig.jpg
$ magick identify -format '%wx%h %[size]' orig.jpg
400x200 3080B
$ ls
orig.jpg
The 2000x1000 source is gone. One file remains, and it is the 400px derivative.
What works
The default path is safe. With no --output, the resized copy goes to
resized-400w/ and the source is untouched:
$ ipro resize orig2.jpg --width 400
$ ls
orig2.jpg resized-400w/
$ magick identify -format '%wx%h' orig2.jpg
2000x1000
So the hazard is specific to --output resolving to the source file's own
directory. . is the obvious way to hit it, but any equivalent path does the same
thing.
How I hit it
Prepping two hero images for a blog post. I cropped the sources, then ran
ipro resize cropped.jpeg --width 1200 --quality 82 --output . intending to write
1200px versions beside the crops. It consumed the crops instead. I happened to
have kept the pre-crop originals, so nothing was actually lost, but only by luck.
A one-command ipro resize photo.jpg --width 1200 --output . on an irreplaceable
photo is unrecoverable.
Expected
Refuse to write when the resolved output path equals the resolved input path.
Something like:
error: output path is the same as the input (orig.jpg).
Use a different --output directory, or pass --force to overwrite.
Possible fixes
- Guard the collision. Compare resolved input and output paths before
writing; abort unless an explicit--forceis given. Smallest change, fixes
the data loss, keeps current behavior available for anyone who wants it. - Put the size in the filename when the output directory is not the
generatedresized-*one, e.g.orig-400w.jpg. This removes the collision
rather than guarding it, and makes--output .do the useful thing people
probably expect. Related to the naming discussion in #21. - Both: name the file by size, and still refuse an exact path collision.
I'd suggest 1 on its own as a fast fix, since it turns silent data loss into a
clear error, and 2 as the better long-term behavior.
Happy to open a PR for the guard if that's useful.
— Emily
- 主要语言
- Python
- 星标
- 1
- 派生
- 0
- 平均合并
- 4 小时 13 分钟
- 30 天内合并 PR
- 2
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
cadentdev/ipro 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 64/100
-
难度 4/5 3-5 天 新手友好度 42/100
-
难度 4/5 3-5 天 新手友好度 50/100
-
难度 5/5 一周以上 新手友好度 45/100
-
难度 4/5 3-5 天 新手友好度 52/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
LearningCircuit/local-deep-research#10161 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
chore: contact address [email protected]可能已有人在做 @larsrollik 今天认领。 未关闭
难度 1/5 1-3 小时 新手友好度 82/100
-
bug
难度 2/5 1-3 小时 新手友好度 80/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
Gustavo-Galvao-e-Silva/panchi#228 ·
维护者通常 1 天内回复