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.
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.
$ make uninstall
If the install was system-wide:
$ sudo make uninstall PREFIX=/usr
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.
trash-restore --sort noneworks: it keeps the scan order and exits 0 (upstream always raisedTypeErrorbecause theNoSorterclass was returned where an instance was expected).XDG_DATA_HOME: an empty value is treated like an unset one, so the$HOME/.local/share/Trashfallback applies (upstream used presence-only checking, making the home trash literally/Trash).- Undated restore entries sort last (printing
None) instead of raisingTypeErrorwhen sorted among real dates. trash-restore's zero-candidates message names the searched path:No files trashed from current dir ('<realpath of cwd>')without apathargument, elseNo files trashed from '<path>'(upstream always claimed "current dir").trash-restorehonorsTRASH_VOLUMESlike list/empty/rm (upstream ignored it).trash-rm ''(empty pattern) matches nothing and exits 0 (upstream crashed withIndexErroron a non-empty trash).- Non-UTF-8 or otherwise unparsable trashinfo files are warned about and
skipped, exit 0, in
trash-listandtrash-rm(upstream crashed withUnicodeDecodeError, exit 1), and intrash-emptywith adaysargument, which upstream also crashed on;trash-restore, andtrash-emptywithoutdays(which never reads the files), behaved leniently already. trash-empty'sdaysoverflow is a clean usage error: a value whose cutoff would leave the representable date range (years 1..9999), e.g.99999999999999999999, givestrash-empty: error: argument days: value out of range: '<value>', exit 2 (upstream died on an uncaughtOverflowError, exit 1).trash-put -i/trash-empty -ion EOF print<prog>: EOF while reading the answeron stderr and exit 1 (upstream: unhandledEOFErrortraceback).trash-empty -iwith zero trash dirs printsNo trash directories to empty.with a newline and exits 0 without waiting for input (upstream used the text as aninput()prompt).trash-list --all-usersskips trash dirs of other users that cannot be read and exits 0 (upstream died onPermissionError).- Trashing a read-only directory works: when
rename(2)fails withEACCESbecause moving a directory to a different parent rewrites its..entry (which needs write access to the directory itself on Linux and FreeBSD),trash-putgrants 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-restoremoves such a directory back the same way, andtrash-empty/trash-rmgive the user's own read-only directories owner access before removing their contents. - Repeated indexes at the
trash-restoreprompt restore once:2,0,2restores entries 2 and 0, in that order (upstream restored entry 2, then failed the repeat withRefusing to overwrite existing file, exit 1). trash-restoreworks from/: with the working directory at/every entry is under it (upstream searched for the prefix//and found nothing).