Merge pull request #6514 from amyspark/workaround-trash
Cask: refuse to trash root-owned files
This commit is contained in:
commit
77412ad14e
@ -362,7 +362,13 @@ module Cask
|
|||||||
def trash_paths(*paths, command: nil, **_)
|
def trash_paths(*paths, command: nil, **_)
|
||||||
return if paths.empty?
|
return if paths.empty?
|
||||||
|
|
||||||
result = command.run!("/usr/bin/swift", args: [TRASH_SCRIPT, *paths])
|
trashable, untrashable = paths.partition(&:writable?)
|
||||||
|
unless untrashable.empty?
|
||||||
|
opoo "These files cannot be moved to the user's Trash:"
|
||||||
|
$stderr.puts untrashable
|
||||||
|
end
|
||||||
|
|
||||||
|
result = command.run!("/usr/bin/swift", args: [TRASH_SCRIPT, *trashable])
|
||||||
|
|
||||||
# Remove AppleScript's automatic newline.
|
# Remove AppleScript's automatic newline.
|
||||||
result.tap { |r| r.stdout.sub!(/\n$/, "") }
|
result.tap { |r| r.stdout.sub!(/\n$/, "") }
|
||||||
|
|||||||
@ -2,6 +2,11 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
struct swifterr: TextOutputStream {
|
||||||
|
public static var stream = swifterr()
|
||||||
|
mutating func write(_ string: String) { fputs(string, stderr) }
|
||||||
|
}
|
||||||
|
|
||||||
if (CommandLine.arguments.count < 2) {
|
if (CommandLine.arguments.count < 2) {
|
||||||
exit(2)
|
exit(2)
|
||||||
}
|
}
|
||||||
@ -12,10 +17,11 @@ for item in CommandLine.arguments[1...] {
|
|||||||
do {
|
do {
|
||||||
let path: URL = URL(fileURLWithPath: item)
|
let path: URL = URL(fileURLWithPath: item)
|
||||||
try manager.trashItem(at: path, resultingItemURL: nil)
|
try manager.trashItem(at: path, resultingItemURL: nil)
|
||||||
print(path)
|
print(path, terminator: "\0")
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
print("\0")
|
print(error.localizedDescription, to: &swifterr.stream)
|
||||||
|
exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user