LoginSignup
7
2

More than 5 years have passed since last update.

Re:GNU/Linuxにおけるゴミ箱ディレクトリは.Trash/$uid/と.Trash-$uid/のどちらが正しいのか

Last updated at Posted at 2017-10-15

きっかけ

@ncaq 氏が
GNU/Linuxにおけるゴミ箱ディレクトリは.Trash/$uid/と.Trash-$uid/のどちらが正しいのか調べていたらtrash-cliのコメントが動作と違ったのでissueを開きました - ncaq
というブログを書いていて、
trash-cli prefers $topdir/.Trash-$uid to the trash directory over $topdir/.Trash/$uid · Issue #108 · andreafrancia/trash-cli
Issueも投げられていた。

しかし specを読むうちに、あれなんか違わね?と思った。

ncaq 氏の記事の要約

$topdir/.Trash/$uidを使うべきなはずなのになんでnautilus(gio trash)もtrash-cliも$topdir/.Trash-$uid使っちゃうの?これっておかしくない?

参照するspec

Trash specification
https://specifications.freedesktop.org/trash-spec/trashspec-latest.html

場面設定

  1. spec曰く、通常使うゴミ箱ディレクトリとしてhome trashディレクトリがある。
  2. 削除したいファイルが、home trashディレクトリが存在しないドライブ/ファイルシステムにある場合、これを使おうとするとコピーコストがかかるのでマウントされているすべてのドライブ/ファイルシステムに(home trashディレクトリが存在するドライブ/ファイルシステムを除く)ゴミ箱ディレクトリを作れる(MAY)
  3. 作れる場所は$topdir/.Trash/$uid$topdir/.Trash-$uid($uidはユーザー固有の数字)

specを解読した

解読の鍵となるのは

https://specifications.freedesktop.org/trash-spec/trashspec-latest.html
The following paragraph applies ONLY to the case when the implementation supports trashing in the top directory, and a $topdir/.Trash does not exist or has not passed the checks:

The following paragraphってのは$topdir/.Trash-$uidの生成の話。

  1. $topdir/.Trashを作成できるのはadministratorだけ((ファイルシステムが対応していたら)sticky bit を作成時に立てる)
  2. すべてのuserは$topdir/.Trashが存在するとき、そこに書き込み権限を持っている
  3. もし$topdir/.Trashが存在して、チェック項目(sticky bitとかsymbolic linkじゃないこととかとか。Trash specificationを参照されたし)をクリアしたら
    1. userは$topdir/.Trash/$uidを生成できる(実装は自動的に生成しなければならない(MUST))
    2. userは$topdir/.Trash/$uidをゴミ箱ディレクトリとして使える
  4. もし$topdir/.Trashが存在しなかったもしくはチェック項目をクリアできなかった場合
    1. userは$topdir/.Trash-$uidを生成できる(実装は自動的に生成しなければならない(MUST))
    2. userは$topdir/.Trash-$uidをゴミ箱ディレクトリとして使える

ncaq氏の検証の考察

2017-10-15T22:21:11 ncaq@akaza/pts/7(0) /mnt/usbstick
% ll
合計 68K
drwxrwxrwx 1 root root  64K 10月 15 22:20 ./
drwxr-xr-x 9 root root 4.0K 10月 16  2015 ../
2017-10-15T22:21:11 ncaq@akaza/pts/7(0) /mnt/usbstick
% touch example
2017-10-15T22:21:17 ncaq@akaza/pts/7(0) /mnt/usbstick
% ll
合計 68K
drwxrwxrwx 1 root root  64K 10月 15 22:21 ./
drwxr-xr-x 9 root root 4.0K 10月 16  2015 ../
-rwxrwxrwx 1 root root    0 10月 15 22:21 example*
2017-10-15T22:21:19 ncaq@akaza/pts/7(0) /mnt/usbstick
% trash-put example
2017-10-15T22:21:31 ncaq@akaza/pts/7(0) /mnt/usbstick
% tree -a 
.
└── [drwxrwxrwx  240]  .Trash-1000/
    ├── [drwxrwxrwx  144]  files/
    │   └── [-rwxrwxrwx    0]  example*
    └── [drwxrwxrwx  168]  info/
        └── [-rwxrwxrwx   59]  example.trashinfo*

3 directories, 2 files

こんな実験をしたそうな。

これをさっきの解読結果を踏まえて考察すると、$topdir/.Trashが存在していない状況下なので、当然$topdir/.Trash/$uidは生成できない。なので$topdir/.Trash-$uidを生成してゴミ箱ディレクトリにしたよ、という状況だとわかる。

これってのはspecに合致していて問題ない。

ncaq氏が問題にしていたtrash-cliのプログラム内のコメント

        """
        Trash a file in the appropriate trash directory.
        If the file belong to the same volume of the trash home directory it
        will be trashed in the home trash directory.
        Otherwise it will be trashed in one of the relevant volume trash
        directories.
        Each volume can have two trash directories, they are
            - $volume/.Trash/$uid
            - $volume/.Trash-$uid
        Firstly the software attempt to trash the file in the first directory
        then try to trash in the second trash directory.
        """

これだ。言っていることとしては、$volume/.Trash/$uidがゴミ箱ディレクトリにできるかまず調べて、だめだったら$volume/.Trash-$uidをゴミ箱ディレクトリにするってことだから、ちょっと端折りすぎ感あるけどspecといっていることは変わらないので問題ない

まとめ

という私の解釈があっているといいな(願望)

間違ってるよ、って人は
trash-cli prefers $topdir/.Trash-$uid to the trash directory over $topdir/.Trash/$uid · Issue #108 · andreafrancia/trash-cli
まで

追記

ncaq commented 2017年10月16日 2:17 JST
I misread Spec.
I understand to implementation and comment of trash-cli is correct.
Thank @yumetodo .
I close this issue.

という感じでIssueが閉じた

License

CC BY 4.0

CC-BY icon.svg

7
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
2