Skip to content
skeetoPublic

About

FreeDesktop trash can CLI

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lean-trash-cli: efficient FreeDesktop trash can CLI

A feature-complete rewrite of the original trash-cli in a language more suited to systems programming. Its purpose is to surpass the original in every aspect. The project includes a comprehensive test suite that runs against a virtual file system.

Install

Runs on Linux and FreeBSD. Requires make (GNU or BSD) and a C23 compiler such as GCC 13 or later, or Clang 18 or later; on FreeBSD the base system's Clang suffices from 14.1 on. By default installs to ~/.local:

$ make install

Or a system-wide installation:

$ sudo make install PREFIX=/usr

On FreeBSD, use PREFIX=/usr/local instead.

Uninstall

$ make uninstall

If the install was system-wide:

$ sudo make uninstall PREFIX=/usr

Testing

The tests create no files and do not touch the file system: they run the commands against a virtual Linux, so the system calls of the platform layer (Linux or FreeBSD) at the bottom of trash.c are exercised only by real use. Linux's mount table parsing is shared with the virtual OS, which serves it virtual /proc files, so the suite tests that part; FreeBSD's mount table comes straight from getfsstat(2).

$ make check

The test build needs only a C23 compiler and the standard C library, so the suite also runs on hosts other than Linux, such as macOS, the BSDs, or Windows with Mingw-w64.

Upstream bugs fixed/avoided

  1. trash-restore --sort none works: it keeps the scan order and exits 0 (upstream always raised TypeError because the NoSorter class was returned where an instance was expected).
  2. XDG_DATA_HOME: an empty value is treated like an unset one, so the $HOME/.local/share/Trash fallback applies (upstream used presence-only checking, making the home trash literally /Trash).
  3. Undated restore entries sort last (printing None) instead of raising TypeError when sorted among real dates.
  4. trash-restore's zero-candidates message names the searched path: No files trashed from current dir ('<realpath of cwd>') without a path argument, else No files trashed from '<path>' (upstream always claimed "current dir").
  5. trash-restore honors TRASH_VOLUMES like list/empty/rm (upstream ignored it).
  6. trash-rm '' (empty pattern) matches nothing and exits 0 (upstream crashed with IndexError on a non-empty trash).
  7. Non-UTF-8 or otherwise unparsable trashinfo files are warned about and skipped, exit 0, in trash-list and trash-rm (upstream crashed with UnicodeDecodeError, exit 1), and in trash-empty with a days argument, which upstream also crashed on; trash-restore, and trash-empty without days (which never reads the files), behaved leniently already.
  8. trash-empty's days overflow is a clean usage error: a value whose cutoff would leave the representable date range (years 1..9999), e.g. 99999999999999999999, gives trash-empty: error: argument days: value out of range: '<value>', exit 2 (upstream died on an uncaught OverflowError, exit 1).
  9. trash-put -i/trash-empty -i on EOF print <prog>: EOF while reading the answer on stderr and exit 1 (upstream: unhandled EOFError traceback).
  10. trash-empty -i with zero trash dirs prints No trash directories to empty. with a newline and exits 0 without waiting for input (upstream used the text as an input() prompt).
  11. trash-list --all-users skips trash dirs of other users that cannot be read and exits 0 (upstream died on PermissionError).
  12. Trashing a read-only directory works: when rename(2) fails with EACCES because moving a directory to a different parent rewrites its .. entry (which needs write access to the directory itself on Linux and FreeBSD), trash-put grants owner-write for the move and restores the original mode on the backup copy (spec 5.6: only removing from the parent must be allowed). trash-restore moves such a directory back the same way, and trash-empty/trash-rm give the user's own read-only directories owner access before removing their contents.
  13. Repeated indexes at the trash-restore prompt restore once: 2,0,2 restores entries 2 and 0, in that order (upstream restored entry 2, then failed the repeat with Refusing to overwrite existing file, exit 1).
  14. trash-restore works from /: with the working directory at / every entry is under it (upstream searched for the prefix // and found nothing).

About

FreeDesktop trash can CLI

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages