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

What's the difference between trash and macos-trash #1

Open
wolfogre opened this issue Nov 29, 2024 · 2 comments
Open

What's the difference between trash and macos-trash #1

wolfogre opened this issue Nov 29, 2024 · 2 comments

Comments

@wolfogre
Copy link

wolfogre commented Nov 29, 2024

Just a kind question, is it a new wheel, or does it have some new stuff?

I asked like this because I've been using https://hasseg.org/trash/ for years. It can be installed by the standard Homebrew tap.

BTW, there's another similar tool named macos-trash in Homebrew.

PS: I found this repo from https://www.ruanyifeng.com/blog/2024/11/weekly-issue-327.html

@TBXark TBXark changed the title What's the difference between trash What's the difference between trash and macos-trash Nov 29, 2024
@TBXark
Copy link
Owner

TBXark commented Nov 29, 2024

1. trash

Provide two types of deletion logic

  1. It is using NSAppleEventDescriptor to simulate the real deletion operation in the Finder. You can think of it as a wrapper for a Apple Script. Because it did not use the system api, there are now some issues due to years of lack of maintenance.
    https://github.com/ali-rantakari/trash/blob/master/trash.m#L278

  2. Use FSMoveObjectToTrashSync for deletion, but this API has been deprecated since macOS 10.8.
    https://github.com/ali-rantakari/trash/blob/master/trash.m#L378
    https://developer.apple.com/documentation/coreservices/1566651-fsmoveobjecttotrashsync

Although a -F flag bit is provided to let you choose which logic to use, the final implementation is equivalent to rm -rf, which does not provide any support for the rm feature.
https://github.com/ali-rantakari/trash/blob/master/trash.m#L500

2. macos-trash

It only calls try FileManager.default.trashItem(at: url, resultingItemURL: nil), without supporting other features of rm, which is equivalent to rm -rf, and this is quite dangerous.
https://github.com/sindresorhus/macos-trash/blob/main/Sources/trash/main.swift#L12-L14

3. rmtrash

Provides support for all rm features, uses all the latest FileManager APIs, stable compatibility

OVERVIEW: Move files and directories to the trash.

rmtrash is a small utility that will move the file to macOS's Trash rather than obliterating the file (as rm does).

USAGE: rmtrash [--force] [-i] [-I] [--interactive <interactive>] [--one-file-system] [--preserve-root] [--no-preserve-root] [--recursive] [--dir] [--verbose] [--version] [<paths> ...]

ARGUMENTS:
  <paths>                 The files or directories to move to trash.

OPTIONS:
  -f, --force             Ignore nonexistant files, and never prompt before removing.
  -i                      Prompt before every removal.
  -I                      Prompt once before removing more than three files, or when removing recursively. This option is less intrusive than -i, but still gives protection
                          against most mistakes.
  --interactive <interactive>
                          Prompt according to WHEN: never, once (-I), or always (-i). If WHEN is not specified, then prompt always.
  -x, --one-file-system   When removing a hierarchy recursively, skip any directory that is on a file system different from that of the corresponding command line argument
  --preserve-root/--no-preserve-root
                          Do not remove "/" (the root directory), which is the default behavior. (default: --preserve-root)
  -r, -R, --recursive     Recursively remove directories and their contents.
  -d, --dir               Remove empty directories. This option permits you to remove a directory without specifying -r/-R/--recursive, provided that the directory is empty. In
                          other words, rm -d is equivalent to using rmdir.
  -v, --verbose           Verbose mode; explain at all times what is being done.
  --version               Display version information, and exit.
  --version               Show the version.
  --help                  Show help information.

@TBXark TBXark pinned this issue Nov 29, 2024
@TBXark
Copy link
Owner

TBXark commented Nov 29, 2024

Maybe when I get enough stars I can submit a formula to homebrew/core 🤣

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