Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trash-empty crashes with directories without read permission #48

Closed
protist opened this issue Feb 15, 2015 · 3 comments
Closed

trash-empty crashes with directories without read permission #48

protist opened this issue Feb 15, 2015 · 3 comments
Assignees

Comments

@protist
Copy link

protist commented Feb 15, 2015

If a file does not have write permissions, trash-empty crashes.

$ trash-empty 7
Traceback (most recent call last):
  File "/usr/bin/trash-empty", line 5, in <module>
    sys.exit(main())
  File "/usr/lib/python2.7/site-packages/trashcli/cmds.py", line 23, in empty
    ).run(*sys.argv)
  File "/usr/lib/python2.7/site-packages/trashcli/trash.py", line 446, in run
    parse(argv)
  File "/usr/lib/python2.7/site-packages/trashcli/trash.py", line 315, in __call__
    self.default_action()
  File "/usr/lib/python2.7/site-packages/trashcli/trash.py", line 466, in _empty_all_trashdirs
    self.trashdirs.list_trashdirs()
  File "/usr/lib/python2.7/site-packages/trashcli/trash.py", line 388, in list_trashdirs
    self.emit_home_trashcan()
  File "/usr/lib/python2.7/site-packages/trashcli/trash.py", line 393, in emit_home_trashcan
    self.home_trashcan.path_to(return_result_with_volume)
  File "/usr/lib/python2.7/site-packages/trashcli/trash.py", line 83, in path_to
    out('%(HOME)s/.local/share/Trash' % self.environ)
  File "/usr/lib/python2.7/site-packages/trashcli/trash.py", line 392, in return_result_with_volume
    self.on_trash_dir_found(trashcan_path, '/')
  File "/usr/lib/python2.7/site-packages/trashcli/trash.py", line 481, in _analize_trash_directory
    self.trashdir.each_trashinfo(self.on_trashinfo_found)
  File "/usr/lib/python2.7/site-packages/trashcli/trash.py", line 573, in each_trashinfo
    action(os.path.join(self._info_dir(), entry))
  File "/usr/lib/python2.7/site-packages/trashcli/trash.py", line 365, in delete_if_expired
    self._maybe_delete(trashinfo_path)
  File "/usr/lib/python2.7/site-packages/trashcli/trash.py", line 373, in _delete_according_date
    )(contents)
  File "/usr/lib/python2.7/site-packages/trashcli/trash.py", line 629, in __call__
    self.found_deletion_date(date)
  File "/usr/lib/python2.7/site-packages/trashcli/trash.py", line 490, in __call__
    self.then()
  File "/usr/lib/python2.7/site-packages/trashcli/trash.py", line 371, in <lambda>
    lambda: self._delete_unconditionally(trashinfo_path)
  File "/usr/lib/python2.7/site-packages/trashcli/trash.py", line 375, in _delete_unconditionally
    self._trashcan.delete_trashinfo_and_backup_copy(trashinfo_path)
  File "/usr/lib/python2.7/site-packages/trashcli/trash.py", line 348, in delete_trashinfo_and_backup_copy
    self._file_remover.remove_file_if_exists(backup_copy)
  File "/usr/lib/python2.7/site-packages/trashcli/fs.py", line 27, in remove_file_if_exists
    if os.path.exists(path): self.remove_file(path)
  File "/usr/lib/python2.7/site-packages/trashcli/fs.py", line 25, in remove_file
    shutil.rmtree(path)
  File "/usr/lib/python2.7/shutil.py", line 247, in rmtree
    rmtree(fullname, ignore_errors, onerror)
  File "/usr/lib/python2.7/shutil.py", line 239, in rmtree
    onerror(os.listdir, path, sys.exc_info())
  File "/usr/lib/python2.7/shutil.py", line 237, in rmtree
    names = os.listdir(path)
OSError: [Errno 13] Permission denied: '/home/protist/.local/share/Trash/files/jitsi/pkg'
$ ls -ld /home/protist/.local/share/Trash/files/jitsi/pkg
d--------- 2 protist protist 4096 Feb  9 09:49 /home/protist/.local/share/Trash/files/jitsi/pkg

N.B. this is owned by me, and so trash-empty can change its permissions.

$ chmod u+wrx /home/protist/.local/share/Trash/files/jitsi/pkg
$ trash-empty

This works. (N.B. that u+wx is not enough.)

@andreafrancia
Copy link
Owner

trash-empty should skip the file and not change the permissions.

@andreafrancia andreafrancia modified the milestones: far-far-future, when-some-bring-the-solution Aug 12, 2015
@ghost
Copy link

ghost commented Aug 3, 2016

This problem can be reproduced as follows:

$ mkdir test
$ chmod -r test
$ trash-put test
$ trash-empty
Traceback (most recent call last):
  File "/usr/bin/trash-empty", line 5, in <module>
    sys.exit(main())
  File "/usr/lib/python2.7/site-packages/trashcli/cmds.py", line 23, in empty
    ).run(*sys.argv)
  File "/usr/lib/python2.7/site-packages/trashcli/trash.py", line 446, in run
    parse(argv)
  File "/usr/lib/python2.7/site-packages/trashcli/trash.py", line 315, in __call__
    self.default_action()
  File "/usr/lib/python2.7/site-packages/trashcli/trash.py", line 466, in _empty_all_trashdirs
    self.trashdirs.list_trashdirs()
  File "/usr/lib/python2.7/site-packages/trashcli/trash.py", line 388, in list_trashdirs
    self.emit_home_trashcan()
  File "/usr/lib/python2.7/site-packages/trashcli/trash.py", line 393, in emit_home_trashcan
    self.home_trashcan.path_to(return_result_with_volume)
  File "/usr/lib/python2.7/site-packages/trashcli/trash.py", line 83, in path_to
    out('%(HOME)s/.local/share/Trash' % self.environ)
  File "/usr/lib/python2.7/site-packages/trashcli/trash.py", line 392, in return_result_with_volume
    self.on_trash_dir_found(trashcan_path, '/')
  File "/usr/lib/python2.7/site-packages/trashcli/trash.py", line 481, in _analize_trash_directory
    self.trashdir.each_trashinfo(self.on_trashinfo_found)
  File "/usr/lib/python2.7/site-packages/trashcli/trash.py", line 573, in each_trashinfo
    action(os.path.join(self._info_dir(), entry))
  File "/usr/lib/python2.7/site-packages/trashcli/trash.py", line 365, in delete_if_expired
    self._maybe_delete(trashinfo_path)
  File "/usr/lib/python2.7/site-packages/trashcli/trash.py", line 375, in _delete_unconditionally
    self._trashcan.delete_trashinfo_and_backup_copy(trashinfo_path)
  File "/usr/lib/python2.7/site-packages/trashcli/trash.py", line 348, in delete_trashinfo_and_backup_copy
    self._file_remover.remove_file_if_exists(backup_copy)
  File "/usr/lib/python2.7/site-packages/trashcli/fs.py", line 27, in remove_file_if_exists
    if os.path.exists(path): self.remove_file(path)
  File "/usr/lib/python2.7/site-packages/trashcli/fs.py", line 25, in remove_file
    shutil.rmtree(path)
  File "/usr/lib/python2.7/shutil.py", line 239, in rmtree
    onerror(os.listdir, path, sys.exc_info())
  File "/usr/lib/python2.7/shutil.py", line 237, in rmtree
    names = os.listdir(path)
OSError: [Errno 13] Permission denied: '/home/fturco/.local/share/Trash/files/test'

I'm using trash-cli-0.12.9.14.r34.g7913a0b-3 on a Parabola GNU/Linux-libre system.

@andreafrancia andreafrancia removed this from the when-some-bring-the-solution milestone Dec 26, 2016
@protist
Copy link
Author

protist commented Dec 27, 2016

I run trash-empty 7 from a crontab job, so I'd prefer trash-cli to not skip these files silently, otherwise the trash would contain these offending files forever, and I'd never know. Ideally, I'd like it to trash them even if it doesn't have write permissions. Perhaps there could be a -f flag to force deletion, regardless of permissions?

@andreafrancia andreafrancia self-assigned this Dec 27, 2016
andreafrancia added a commit that referenced this issue Dec 27, 2016
@andreafrancia andreafrancia changed the title trash-empty crashes with files without write permission trash-empty crashes with directories without read permission Dec 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants