mv --exchange with one source swaps the entire target directory without -T

未关闭
#16,778 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
rust
领域
cli

调研方向

The bug is in the two-operand branch of exchange_paths in src/uu/mv/src/mv.rs, which passes the target directory itself to exchange_two_paths instead of the path inside it. Read that branch and compare it with the -T and multiple-source handling, then reproduce with the shell snippet in the issue. Done means one source with a populated target directory and no -T swaps the source with target/<source basename>, exits 0 as GNU does, and a regression test in the mv test suite covers this case.

由索引模型根据 Issue 内容生成。

描述

With one source and no -T, mv --exchange manifest release/ swaps the file with the whole release directory and exits 0. Unrelated files move with it.

work=$(mktemp -d) && cd "$work" || exit 1
mkdir release
printf 'staged\n' > manifest
printf 'current\n' > release/manifest
printf 'other\n' > release/notes
mv --exchange manifest release/
find . -type f | LC_ALL=C sort

GNU swaps manifest and release/manifest. The unrelated file stays at release/notes. On uutils, release is now a regular file containing staged, and the entire directory is now at manifest (including manifest/notes and manifest/manifest).

Repeating in a fresh directory without release/manifest, GNU exits 1 and leaves both paths in place. uutils still exchanges the directory and exits 0. With explicit -T, both implementations exchange the whole directory.

Verified on x86_64 Linux with uutils 0.12.0, 0.13.0 and main at 8b16a3dca86ae91df73db3d375205eb7718c4c03 against GNU 9.7 and 9.12. The two-operand arm of exchange_paths passes the target directory itself to exchange_two_paths. Existing tests cover -T and multiple sources. A regression test with one source and a populated target directory without -T would catch this. https://github.com/uutils/coreutils/blob/8b16a3dca86ae91df73db3d375205eb7718c4c03/src/uu/mv/src/mv.rs#L640-L657

主要语言
Rust
星标
24.4k
派生
2.2k
平均合并
2 天 23 小时
30 天内合并 PR
402

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

uutils/coreutils 的其他 Issue

查看 uutils/coreutils 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。