-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
[BUG] trash moves files to wrong user when executing with elevated privileges #11
Comments
Currently, it's just reverting back to non-sudo user: macos-trash/Sources/trash/util.swift Lines 26 to 37 in e5250fa
I would be happy to see this improved, but it's not something I plan to work on. Related issue: sindresorhus/trash-cli#28 |
This is how to get the console username: import SystemConfiguration
func getConsoleUser() -> String? {
SCDynamicStoreCopyConsoleUser(nil, nil, nil) as String?
}
getConsoleUser() |
I have read the issue you pointed to (#28), and your reasoning there makes sense, also what @russelldavis wrote. Personally I think it wouldn't be a good idea to change the ownership or permissions of the parent directory of the file specified for removal, when the user runs Maybe, for these cases, you could rather add an Or you concoct some weird workaround that relies on neither the system API nor the Finder. But the users can probably do that themselves with a shellscript using |
I think falling back to Finder automatically if it fails and the terminal is interactive is an ok workaround. |
Ah, yes, the interactive issue. Maybe you could use the Another thing would be the following: when executing |
If anyone's interested… this should probably do it in a shell script context:
|
It's much faster to pass all paths to the system API than to iterate through them. |
Definitely. I use it in a shell script anyway and cycle through the filepaths, similar to the snippet above… so I have my own workaround for that. ;) The only implementation I could think of is another argument, e.g. |
Have you by any chance found a non-Finder solution? |
I have disabled Finder too, and I'm using the following workaround. When I need the Finder, I'm toggling it with the following shell script that's mapped to my TouchBar using BetterTouchTool. (You can also map it differently, of course.)
Additionally, I have a enabled a user LaunchAgent which runs every 30 seconds and auto-quits Finder whenever Finder has launched without the above toggleFinder script:
The
In addition, I'm using macos-trash as part of a workflow to delete my files, and in that workflow I've added a simple check: if Finder is already running before |
Thanks for your detailed guide on how to get rid of the pesky Finder, but am I correct to assume from this that there is no known fix, i.e., it's impossible to correctly identify the user's Trash and move files there instead of using the system Trash? |
Let's say we have a file
/Users/Shared/foo.txt
owned byroot:wheel
.Moving this to the currently logged-in user's trash works fine in Finder: you just have to enter your admin password.
Problems arise when using
trash
instead:sudo trash /Users/Shared/foo
doesn't work, and that's probably OK, but a question nonetheless: is there a reason whysudo trash
doesn't work?osascript -e 'do shell script "trash /Users/Shared/foo" with administrator privileges'
… but the file actually doesn't wind up in the the user's trash directory~/.Trash
, as it does in Finder, but in/private/var/root/.Trash
.So it seems that the
trash
CLI is only checking which user is executing the command (0
), but not if that's also the same as the logged-in user, e.g.501
.If that's true, the
trash
CLI should determine the actual home folder of the executing user by running the equivalent ofeval echo "~$(scutil <<< \"show State:/Users/ConsoleUser\" | awk '/Name :/ && ! /loginwindow/ { print $3 }')"
, and then use the trash directory of that user.This bug should be fixed, because users should be able to move non-writable files to their own trash, in the same way it's possible in the Finder.
The text was updated successfully, but these errors were encountered: