mirror of
https://github.com/transmission/transmission
synced 2025-02-21 21:57:01 +00:00
Migrate deprecated NSWorkspaceRecycleOperation (#2113)
Also make code flow less nested Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
parent
7693ef69bf
commit
1449ccac49
1 changed files with 19 additions and 21 deletions
|
@ -574,30 +574,28 @@ bool trashDataFile(char const* filename, tr_error** error)
|
|||
|
||||
+ (BOOL)trashFile:(NSString*)path error:(NSError**)error
|
||||
{
|
||||
//attempt to move to trash
|
||||
if (![NSWorkspace.sharedWorkspace performFileOperation:NSWorkspaceRecycleOperation source:path.stringByDeletingLastPathComponent
|
||||
destination:@""
|
||||
files:@[ path.lastPathComponent ]
|
||||
tag:nil])
|
||||
// Attempt to move to trash
|
||||
if ([NSFileManager.defaultManager trashItemAtURL:[NSURL fileURLWithPath:path] resultingItemURL:nil error:nil])
|
||||
{
|
||||
//if cannot trash, just delete it (will work if it's on a remote volume)
|
||||
NSError* localError;
|
||||
if (![NSFileManager.defaultManager removeItemAtPath:path error:&localError])
|
||||
{
|
||||
NSLog(@"old Could not trash %@: %@", path, localError.localizedDescription);
|
||||
if (error != nil)
|
||||
{
|
||||
*error = localError;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
else
|
||||
{
|
||||
NSLog(@"old removed %@", path);
|
||||
}
|
||||
NSLog(@"Old moved to Trash %@", path);
|
||||
return YES;
|
||||
}
|
||||
|
||||
return YES;
|
||||
// If cannot trash, just delete it (will work if it's on a remote volume)
|
||||
NSError* localError;
|
||||
if ([NSFileManager.defaultManager removeItemAtPath:path error:&localError])
|
||||
{
|
||||
NSLog(@"Old removed %@", path);
|
||||
return YES;
|
||||
}
|
||||
|
||||
NSLog(@"Old could not be trashed or removed %@: %@", path, localError.localizedDescription);
|
||||
if (error != nil)
|
||||
{
|
||||
*error = localError;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)moveTorrentDataFileTo:(NSString*)folder
|
||||
|
|
Loading…
Reference in a new issue