Fix trash.swift
without arguments.
This commit is contained in:
parent
299bb1c25f
commit
04493e2dde
@ -24,8 +24,6 @@ module Cask
|
|||||||
:rmdir,
|
:rmdir,
|
||||||
].freeze
|
].freeze
|
||||||
|
|
||||||
TRASH_SCRIPT = (HOMEBREW_LIBRARY_PATH/"cask/utils/trash.swift").freeze
|
|
||||||
|
|
||||||
def self.from_args(cask, **directives)
|
def self.from_args(cask, **directives)
|
||||||
new(cask, directives)
|
new(cask, directives)
|
||||||
end
|
end
|
||||||
@ -360,16 +358,31 @@ module Cask
|
|||||||
def trash_paths(*paths, command: nil, **_)
|
def trash_paths(*paths, command: nil, **_)
|
||||||
return if paths.empty?
|
return if paths.empty?
|
||||||
|
|
||||||
trashable, untrashable = paths.partition(&:writable?)
|
stdout, stderr, = system_command HOMEBREW_LIBRARY_PATH/"cask/utils/trash.swift",
|
||||||
unless untrashable.empty?
|
args: paths,
|
||||||
opoo "These files cannot be moved to the user's Trash:"
|
print_stderr: false
|
||||||
$stderr.puts untrashable
|
|
||||||
|
trashed = stdout.split(":").sort
|
||||||
|
untrashable = stderr.split(":").sort
|
||||||
|
|
||||||
|
return trashed, untrashable if untrashable.empty?
|
||||||
|
|
||||||
|
untrashable.delete_if do |path|
|
||||||
|
Utils.gain_permissions(path, ["-R"], SystemCommand) do
|
||||||
|
system_command! HOMEBREW_LIBRARY_PATH/"cask/utils/trash.swift",
|
||||||
|
args: [path],
|
||||||
|
print_stderr: false
|
||||||
|
end
|
||||||
|
|
||||||
|
true
|
||||||
|
rescue
|
||||||
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
result = command.run!("/usr/bin/swift", args: [TRASH_SCRIPT, *trashable])
|
opoo "The following files could not trashed, please do so manually:"
|
||||||
|
$stderr.puts untrashable
|
||||||
|
|
||||||
# Remove AppleScript's automatic newline.
|
[trashed, untrashable]
|
||||||
result.tap { |r| r.stdout.sub!(/\n$/, "") }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def uninstall_rmdir(*directories, command: nil, **_)
|
def uninstall_rmdir(*directories, command: nil, **_)
|
||||||
|
@ -49,6 +49,7 @@ module Cask
|
|||||||
tried_permissions = true
|
tried_permissions = true
|
||||||
retry # rmtree
|
retry # rmtree
|
||||||
end
|
end
|
||||||
|
|
||||||
unless tried_ownership
|
unless tried_ownership
|
||||||
# in case of ownership problems
|
# in case of ownership problems
|
||||||
# TODO: Further examine files to see if ownership is the problem
|
# TODO: Further examine files to see if ownership is the problem
|
||||||
@ -62,6 +63,8 @@ module Cask
|
|||||||
tried_permissions = false
|
tried_permissions = false
|
||||||
retry # rmtree
|
retry # rmtree
|
||||||
end
|
end
|
||||||
|
|
||||||
|
raise
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
0
Library/Homebrew/cask/utils/quarantine.swift
Normal file → Executable file
0
Library/Homebrew/cask/utils/quarantine.swift
Normal file → Executable file
29
Library/Homebrew/cask/utils/trash.swift
Normal file → Executable file
29
Library/Homebrew/cask/utils/trash.swift
Normal file → Executable file
@ -2,27 +2,30 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
struct swifterr: TextOutputStream {
|
extension FileHandle : TextOutputStream {
|
||||||
public static var stream = swifterr()
|
public func write(_ string: String) {
|
||||||
mutating func write(_ string: String) { fputs(string, stderr) }
|
self.write(string.data(using: .utf8)!)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CommandLine.arguments.count < 2) {
|
var stderr = FileHandle.standardError
|
||||||
exit(2)
|
|
||||||
}
|
|
||||||
|
|
||||||
let manager: FileManager = FileManager()
|
let manager: FileManager = FileManager()
|
||||||
|
|
||||||
|
var success = true
|
||||||
|
|
||||||
for item in CommandLine.arguments[1...] {
|
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)
|
var trashedPath: NSURL!
|
||||||
print(path, terminator: "\0")
|
try manager.trashItem(at: path, resultingItemURL: &trashedPath)
|
||||||
}
|
print((trashedPath as URL).path, terminator: ":")
|
||||||
catch {
|
} catch {
|
||||||
print(error.localizedDescription, to: &swifterr.stream)
|
print(item, terminator: ":", to: &stderr)
|
||||||
exit(1)
|
success = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exit(0)
|
guard success else {
|
||||||
|
exit(1)
|
||||||
|
}
|
||||||
|
@ -199,8 +199,8 @@ shared_examples "#uninstall_phase or #zap_phase" do
|
|||||||
before do
|
before do
|
||||||
allow_any_instance_of(Cask::Artifact::AbstractUninstall).to receive(:trash_paths)
|
allow_any_instance_of(Cask::Artifact::AbstractUninstall).to receive(:trash_paths)
|
||||||
.and_wrap_original do |method, *args|
|
.and_wrap_original do |method, *args|
|
||||||
method.call(*args).tap do |result|
|
method.call(*args).tap do |trashed, _|
|
||||||
FileUtils.rm_rf result.stdout.split("\0")
|
FileUtils.rm_r trashed
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user