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

sudo trash still has no permission #28

Open
fregante opened this issue Jan 13, 2020 · 6 comments
Open

sudo trash still has no permission #28

fregante opened this issue Jan 13, 2020 · 6 comments

Comments

@fregante
Copy link

fregante commented Jan 13, 2020

I'm on macOS 10.15.2

Create

❯ sudo mkdir /Users/wow

❯ sudo mkdir /Users/wow
mkdir: /Users/wow: File exists #

Delete with trash

❯ trash /Users/wow
Error: Command failed: /usr/local/lib/node_modules/trash-cli/node_modules/trash/lib/macos-trash /Users/wow
“wow” couldn’t be moved to the trash because you don’t have permission to access it.

❯ sudo trash /Users/wow
Error: Command failed: /usr/local/lib/node_modules/trash-cli/node_modules/trash/lib/macos-trash /Users/wow
“wow” couldn’t be moved to the trash because you don’t have permission to access it.

Delete with rm

❯ sudo rm -rf /Users/wow

❯ test -d /Users/wow || echo 'no folder'
no folder
@sindresorhus
Copy link
Owner

This behavior is intentional, although, should be better documented.

See: https://github.com/sindresorhus/macos-trash/blob/6f8bf84ff488d3fd64559e632281af184e023191/Sources/trash/main.swift#L6-L7 And the issue that triggered it: sindresorhus/macos-trash#2

If running as sudo, we still want to move it to the users trash and not the root user's trash which is not visible. The problem is that we just call a system API to move the contents to the trash, so the only way to choose the trash directory is to change the permissions of the whole process.

Maybe we could downgrade the permissions of the directory while being sudo, then downgrade the permissions of the process, and then trash it?

@sindresorhus
Copy link
Owner

Maybe we could downgrade the permissions of the directory while being sudo

Not sure if this has to be done recursively.

@russelldavis

This comment has been minimized.

@sindresorhus

This comment has been minimized.

@russelldavis
Copy link

Thanks for following up.

I didn't make this clear in my original comment (apologies), but my suggestion to move files directly to the trash would fix this sudo issue -- so I don't think it's off-topic.

If this issue didn't exist, I'd agree with you on using the API. But being unable to trash files with sudo is a non-trivial shortcoming, and AFAICT, there's no good way to fix this issue while continuing to use the API. Responding to an idea from above:

Maybe we could downgrade the permissions of the directory while being sudo, then downgrade the permissions of the process, and then trash it?

This would result in the file(s) in the trash having downgraded (loosened) permissions, which would be bad from a security perspective, and inconsistent with what Finder does when trashing such files.

Realistically, the location of the Trash folder is going to be extremely stable, and in the rare event that it does change, there'd be plenty of notice to deal with it. So to me, it's worth the tradeoff to fix this otherwise intractable issue.

@sindresorhus
Copy link
Owner

Also see: sindresorhus/macos-trash#11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants