Migrate deprecated NSWorkspaceRecycleOperation (#2113)

Also make code flow less nested

Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
Dzmitry Neviadomski 2021-11-10 21:20:06 +03:00 committed by GitHub
parent 7693ef69bf
commit 1449ccac49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 21 deletions

View File

@ -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