andreafrancia / trash-cli

Command line interface to the freedesktop.org trashcan.
GNU General Public License v2.0
3.63k stars 177 forks source link

Deleting directory without permissions first tries to copy the entire directory #146

Open sourcejedi opened 5 years ago

sourcejedi commented 5 years ago

I found this when I tried to trash a directory tree created using sudo debootstrap. GNOME Files says this doesn't work. However, trash-cli takes a long time to say that it doesn't work... because it falls back to copying the entire directory tree first.

$ apt-cache show trash-cli | head -n2
Package: trash-cli
Version: 0.12.9.14-2.1

$ head -n1 /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"

$ mkdir a
$ dd if=/dev/zero of=a/b bs=1M count=1000
1000+0 records in
1000+0 records out
1048576000 bytes (1.0 GB, 1000 MiB) copied, 4.25377 s, 247 MB/s
$ chmod a-w a

$ time trash a
trash: cannot trash directory `a'

real    0m6.971s
user    0m0.244s
sys 0m1.572s
$ trash a
^C
Traceback (most recent call last):
  File "/usr/bin/trash", line 5, in <module>
    sys.exit(main())
  File "/usr/lib/python2.7/dist-packages/trashcli/cmds.py", line 10, in put
    ).run(sys.argv)
  File "/usr/lib/python2.7/dist-packages/trashcli/trash.py", line 548, in run
    self.trash_all(args)
  File "/usr/lib/python2.7/dist-packages/trashcli/trash.py", line 557, in trash_all
    self.trash(arg)
  File "/usr/lib/python2.7/dist-packages/trashcli/trash.py", line 560, in trash
    self.trashcan.trash(arg)
  File "/usr/lib/python2.7/dist-packages/trashcli/trash.py", line 324, in trash
    trashed_file = trash_dir.trash(file)
  File "/usr/lib/python2.7/dist-packages/trashcli/trash.py", line 80, in trash
    move(path, trashed_file.actual_path)
  File "/usr/lib/python2.7/dist-packages/trashcli/fs.py", line 47, in move
    return shutil.move(path, str(dest))
  File "/usr/lib/python2.7/shutil.py", line 299, in move
    copytree(src, real_dst, symlinks=True)
  File "/usr/lib/python2.7/shutil.py", line 192, in copytree
    copy2(srcname, dstname)
  File "/usr/lib/python2.7/shutil.py", line 130, in copy2
    copyfile(src, dst)
  File "/usr/lib/python2.7/shutil.py", line 84, in copyfile
    copyfileobj(fsrc, fdst)
  File "/usr/lib/python2.7/shutil.py", line 49, in copyfileobj
    buf = fsrc.read(length)
KeyboardInterrupt