Abort copy file if target is child of source

This commit is contained in:
Allan Odgaard
2014-02-25 15:56:13 +07:00
parent 6cbf04547e
commit 0663a39bcf

View File

@@ -128,18 +128,22 @@ NSString* const OakFileManagerPathKey = @"directory";
- (BOOL)doCreateCopy:(NSURL*)dstURL ofURL:(NSURL*)srcURL window:(NSWindow*)window
{
BOOL res;
NSError* error;
if(res = [[NSFileManager defaultManager] copyItemAtURL:srcURL toURL:dstURL error:&error])
BOOL res = NO;
NSError* error = nil;
if(path::is_child([[[dstURL filePathURL] path] fileSystemRepresentation], [[[srcURL filePathURL] path] fileSystemRepresentation]))
{
error = [NSError errorWithDomain:NSPOSIXErrorDomain code:ENOTSUP userInfo:nil];
}
else if(res = [[NSFileManager defaultManager] copyItemAtURL:srcURL toURL:dstURL error:&error])
{
[[[window undoManager] prepareWithInvocationTarget:self] doRemoveCopy:dstURL ofURL:srcURL window:window];
[self playSound:OakSoundDidMoveItemUISound];
[self postDidChangeContentsOfDirectory:[[dstURL path] stringByDeletingLastPathComponent]];
}
else
{
if(!res && error)
[window presentError:error];
}
return res;
}