Link copying fix

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@13052 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2002-03-09 11:46:24 +00:00
parent 2453f3e7f1
commit 8921d84a91
2 changed files with 60 additions and 34 deletions

View file

@ -1,3 +1,9 @@
2002-03-09 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSFileManager.m: Change copy so that, if the source argument
is a symbolic link, we copy the link rather than the thing it points
to.
2002-03-08 Richard Frith-Macdonald <rfm@gnu.org> 2002-03-08 Richard Frith-Macdonald <rfm@gnu.org>
* Source/Unicode.m: Added BIG5 encoding * Source/Unicode.m: Added BIG5 encoding

View file

@ -387,69 +387,89 @@ static NSFileManager* defaultManager = nil;
toPath: (NSString*)destination toPath: (NSString*)destination
handler: handler handler: handler
{ {
BOOL sourceIsDir;
BOOL fileExists; BOOL fileExists;
NSDictionary *attributes; NSDictionary *attrs;
NSString *fileType;
fileExists = [self fileExistsAtPath: source isDirectory: &sourceIsDir];
if (!fileExists)
return NO;
attrs = [self _attributesAtPath: source traverseLink: NO forCopy: YES];
if (attrs == nil)
{
return NO;
}
fileExists = [self fileExistsAtPath: destination]; fileExists = [self fileExistsAtPath: destination];
if (fileExists) if (fileExists)
return NO; {
return NO;
attributes = [self _attributesAtPath: source traverseLink: NO forCopy: YES]; }
fileType = [attrs objectForKey: NSFileType];
if (sourceIsDir) if ([fileType isEqualToString: NSFileTypeDirectory] == YES)
{ {
/* If destination directory is a descendant of source directory copying /* If destination directory is a descendant of source directory copying
isn't possible. */ isn't possible. */
if ([[destination stringByAppendingString: @"/"] if ([[destination stringByAppendingString: @"/"]
hasPrefix: [source stringByAppendingString: @"/"]]) hasPrefix: [source stringByAppendingString: @"/"]])
return NO; {
return NO;
}
[handler fileManager: self willProcessPath: destination]; [handler fileManager: self willProcessPath: destination];
if (![self createDirectoryAtPath: destination attributes: attributes]) if ([self createDirectoryAtPath: destination attributes: attrs] == NO)
{ {
if (handler) if (handler)
{ {
NSDictionary* errorInfo NSDictionary* errorInfo
= [NSDictionary dictionaryWithObjectsAndKeys: = [NSDictionary dictionaryWithObjectsAndKeys:
destination, @"Path", destination, @"Path", _lastError, @"Error", nil];
_lastError, @"Error",
nil];
return [handler fileManager: self return [handler fileManager: self
shouldProceedAfterError: errorInfo]; shouldProceedAfterError: errorInfo];
} }
else else
return NO; {
return NO;
}
}
if ([self _copyPath: source toPath: destination handler: handler] == NO)
{
return NO;
} }
} }
else if ([fileType isEqualToString: NSFileTypeSymbolicLink] == YES)
if (sourceIsDir)
{ {
if (![self _copyPath: source toPath: destination handler: handler]) NSString *path;
return NO; BOOL result;
else
[handler fileManager: self willProcessPath: source];
path = [self pathContentOfSymbolicLinkAtPath: source];
result = [self createSymbolicLinkAtPath: destination pathContent: path];
if (result == NO)
{ {
[self changeFileAttributes: attributes atPath: destination]; if (handler != nil)
return YES; {
NSDictionary *errorInfo
= [NSDictionary dictionaryWithObjectsAndKeys:
source, @"Path", destination, @"ToPath",
@"cannot link to file", @"Error",
nil];
result = [handler fileManager: self
shouldProceedAfterError: errorInfo];
}
if (result == NO)
{
return NO;
}
} }
} }
else else
{ {
[handler fileManager: self willProcessPath: source]; [handler fileManager: self willProcessPath: source];
if (![self _copyFile: source toFile: destination handler: handler]) if ([self _copyFile: source toFile: destination handler: handler] == NO)
return NO;
else
{ {
[self changeFileAttributes: attributes atPath: destination]; return NO;
return YES;
} }
} }
[self changeFileAttributes: attrs atPath: destination];
return NO; return YES;
} }
- (BOOL) movePath: (NSString*)source - (BOOL) movePath: (NSString*)source