Skip to content

Commit 99757de

Browse files
committed
Revert "Replace manual trash implementation with NSFileManager's trashItemAtURL (#2781)"
ad6481b
1 parent de3d0f7 commit 99757de

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

GitUpKit/Core/GCFoundation.m

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,19 @@ - (BOOL)fileExistsAtPath:(NSString*)path followLastSymlink:(BOOL)followLastSymli
3939
#if !TARGET_OS_IPHONE
4040

4141
- (BOOL)moveItemAtPathToTrash:(NSString*)path error:(NSError**)error {
42-
return [self trashItemAtURL:[NSURL fileURLWithPath:path] resultingItemURL:NULL error:error];
42+
NSString* trashPath = [NSSearchPathForDirectoriesInDomains(NSTrashDirectory, NSUserDomainMask, YES) firstObject];
43+
if (!trashPath) {
44+
GC_SET_GENERIC_ERROR(@"Unable to find Trash");
45+
return NO;
46+
}
47+
NSString* extension = path.pathExtension;
48+
NSString* name = [path.lastPathComponent stringByDeletingPathExtension];
49+
NSString* destinationPath = [trashPath stringByAppendingPathComponent:[name stringByAppendingPathExtension:extension]];
50+
NSUInteger counter = 0;
51+
while ([self fileExistsAtPath:destinationPath followLastSymlink:NO]) {
52+
destinationPath = [trashPath stringByAppendingPathComponent:[[NSString stringWithFormat:@"%@ (%lu)", name, ++counter] stringByAppendingPathExtension:extension]];
53+
}
54+
return [self moveItemAtPath:path toPath:destinationPath error:error];
4355
}
4456

4557
#endif

0 commit comments

Comments
 (0)