人間とウェブの未来

「ウェブの歴史は人類の歴史の繰り返し」という観点から色々勉強しています。

mvコマンドの--strip-trailing-slashesをデフォルト有効にして大丈夫か?

mvに--strip-trailing-slashesというGNUオプションがあるのは皆さんご存知だと思います。

指定された全ての引き数について、 後ろに付いているスラッシュを取り除く。 これは mkdir a; ln -s a la; mv la/ b' のような場合に役立つ。 この場合 POSIX の要求により、 mv はシンボリックリンクla' ではなく ディレクトリ `a' を実際に移動してしまう。

ref: http://linuxjm.osdn.jp/html/gnumaniak/man1/mv.1.html

これ、tab補完をする癖の付いている人が、例えば/にリンクを貼ったsymlinkファイルrootを不用意に別パーティションにmvしようとしたときに、

sudo mv root/ /other_partision/dir/

とかしちゃうと当然システムが壊れちゃうのですが、こういう場合でも--strip-trailing-slashesが効いていると、root//がremoveされた後に処理されるので、シンボリックリンクファイルがmvされ、結果的に助かります。

で、--strip-trailing-slashesについて色々調べていると、

Some GNU programs (at least cp and mv) allow you to remove any trailing slashes from each source argument before operating on it. The --strip-trailing-slashes option enables this behavior.

This is useful when a source argument may have a trailing slash and specify a symbolic link to a directory. This scenario is in fact rather common because some shells can automatically append a trailing slash when performing file name completion on such symbolic links. Without this option, mv, for example, (via the system’s rename function) must interpret a trailing slash as a request to dereference the symbolic link and so must rename the indirectly referenced directory and not the symbolic link. Although it may seem surprising that such behavior be the default, it is required by POSIX and is consistent with other parts of that standard.

ref: https://www.gnu.org/software/coreutils/manual/html_node/Trailing-slashes.html

というように、標準化とかその手の歴史的経緯でデフォルトになっていないという感じなんですよね。

なので、自分が手元で使うmvとかは、coreutilsのmv.cに例えば以下のようなパッチを当てて、オプションとか関係なくデフォルト--strip-trailing-slashesでmvを使いたいんですが、

--- src/mv.c.orig       2015-06-26 17:04:19.000000000 +0000
+++ src/mv.c    2015-07-28 12:57:14.100068252 +0000
@@ -258,8 +258,7 @@
      function that ignores a trailing slash.  I believe the GNU/Linux
      rename semantics are POSIX and susv2 compliant.  */
 
-  if (remove_trailing_slashes)
-    strip_trailing_slashes (source);
+  strip_trailing_slashes (source);
 
   if (dest_is_dir)
     {

こうしてしまうと、 とある状況で動作として問題となる ことってあるのですかねぇ?

自分の思う範囲で、mvのsource側に/をつけないと困る状況が思いつかないんですが、状況によってはあるのかなぁと不安に思っております。