mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
chore: remove applescript from trash (#50067)
Previously, when trashItemAtURL: failed (e.g. on network shares or under app translocation), the code fell back to constructing an AppleScript that interpolated the bundle path directly into a string literal via %@ with no escaping. This was fragile and unnecessary — trashItemAtURL: has been the standard API since 10.8 and covers the relevant cases. The fix simply removes the AppleScript fallback entirely, so Trash() now returns the result of trashItemAtURL: directly. Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
@@ -270,34 +270,10 @@ void Relaunch(NSString* destinationPath) {
|
||||
}
|
||||
|
||||
bool Trash(NSString* path) {
|
||||
bool result = false;
|
||||
|
||||
if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_8) {
|
||||
result = [[NSFileManager defaultManager]
|
||||
trashItemAtURL:[NSURL fileURLWithPath:path]
|
||||
resultingItemURL:nil
|
||||
error:nil];
|
||||
}
|
||||
|
||||
// As a last resort try trashing with AppleScript.
|
||||
// This allows us to trash the app in macOS Sierra even when the app is
|
||||
// running inside an app translocation image.
|
||||
if (!result) {
|
||||
auto* code = R"str(
|
||||
set theFile to POSIX file "%@"
|
||||
tell application "Finder"
|
||||
move theFile to trash
|
||||
end tell
|
||||
)str";
|
||||
NSAppleScript* appleScript = [[NSAppleScript alloc]
|
||||
initWithSource:[NSString stringWithFormat:@(code), path]];
|
||||
NSDictionary* errorDict = nil;
|
||||
NSAppleEventDescriptor* scriptResult =
|
||||
[appleScript executeAndReturnError:&errorDict];
|
||||
result = (scriptResult != nil);
|
||||
}
|
||||
|
||||
return result;
|
||||
return [[NSFileManager defaultManager]
|
||||
trashItemAtURL:[NSURL fileURLWithPath:path]
|
||||
resultingItemURL:nil
|
||||
error:nil];
|
||||
}
|
||||
|
||||
bool DeleteOrTrash(NSString* path) {
|
||||
|
||||
Reference in New Issue
Block a user