Recursive cp overwrites files one directory too high on Linux when the source name ends in a literal backslash and dot

オープン 初心者向け
#16,808 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
rust
領域
cli

調査の方向性

バグは src/uu/cp/src/copydir.rs の再帰コピーで使われるサフィックスのヘルパー(122-146 行付近)にあり、すべてのプラットフォームでバックスラッシュを区切り文字として扱っています。そこから始めて、issue の再現手順をローカルビルドに対して実行してください。完了とは、Linux 上で draft\. という名前のソースが archive/draft\./notes にコピーされ、archive/notes を上書きせず、一方で Windows の区切り文字の扱いはこれまでどおりに動作することです。

索引モデルが issue の本文から書いたものです。

説明

On Linux, backslash is a literal filename character. Recursive cp treats a source basename ending in \. like the special suffix /. and overwrites files directly in the destination.

work=$(mktemp -d) && cd "$work" || exit 1
src='draft\.'
mkdir "$src" archive
printf 'incoming\n' > "$src/notes"
printf 'original\n' > archive/notes
cp -R "$src" archive
printf 'cp exit=%s\n' "$?"
cat archive/notes
test -f "archive/$src/notes" && echo present || echo missing

uutils 0.12.0, 0.13.0 and main at 85dd1ff print cp exit=0, incoming, missing. The original destination file is overwritten and the expected subdirectory is absent. GNU 9.7 and 9.12 print cp exit=0, original, present. The copied file under the source basename contains incoming.

Tested on x86_64 Linux. The same overwrite occurs with cp -a and with overlapping files in deeper subdirectories. A source named draft. works correctly on all five builds.

The suffix helper treats both slash and backslash as separators regardless of platform. The Unix check should recognize only slash. Source

主要言語
Rust
スター
24.4k
フォーク
2.2k
平均マージ
2日 17時間
マージ済み PR(30日)
383

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

uutils/coreutils のほかの issue

uutils/coreutils の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。