@@ -460,41 +460,52 @@ } - (void)copyItemAtPath: (OFString *)source toPath: (OFString *)destination { + void *pool = objc_autoreleasePoolPush(); + + [self copyItemAtURL: [OFURL fileURLWithPath: source] + toURL: [OFURL fileURLWithPath: destination]]; + + objc_autoreleasePoolPop(pool); +} + +- (void)copyItemAtURL: (OFURL *)source + toURL: (OFURL *)destination +{ void *pool; of_file_attributes_t attributes; of_file_type_t type; if (source == nil || destination == nil) @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); - if ([self fileExistsAtPath: destination]) + if ([self fileExistsAtURL: destination]) @throw [OFCopyItemFailedException - exceptionWithSourcePath: source - destinationPath: destination - errNo: EEXIST]; + exceptionWithSourceURL: source + destinationURL: destination + errNo: EEXIST]; @try { - attributes = [self attributesOfItemAtPath: source]; + attributes = [self attributesOfItemAtURL: source]; } @catch (OFRetrieveItemAttributesFailedException *e) { @throw [OFCopyItemFailedException - exceptionWithSourcePath: source - destinationPath: destination - errNo: [e errNo]]; + exceptionWithSourceURL: source + destinationURL: destination + errNo: [e errNo]]; } type = [attributes fileType]; if ([type isEqual: of_file_type_directory]) { OFArray *contents; @try { - [self createDirectoryAtPath: destination]; + [self createDirectoryAtURL: destination]; #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS of_file_attribute_key_t key = of_file_attribute_key_posix_permissions; OFNumber *permissions = [attributes objectForKey: key]; @@ -501,67 +512,70 @@ of_file_attributes_t destinationAttributes = [OFDictionary dictionaryWithObject: permissions forKey: key]; [self setAttributes: destinationAttributes - ofItemAtPath: destination]; + ofItemAtURL: destination]; #endif - contents = [self contentsOfDirectoryAtPath: source]; + contents = [self contentsOfDirectoryAtURL: source]; } @catch (id e) { /* * Only convert exceptions to OFCopyItemFailedException * that have an errNo property. This covers all I/O * related exceptions from the operations used to copy * an item, all others should be left as is. */ if ([e respondsToSelector: @selector(errNo)]) @throw [OFCopyItemFailedException - exceptionWithSourcePath: source - destinationPath: destination - errNo: [e errNo]]; + exceptionWithSourceURL: source + destinationURL: destination + errNo: [e errNo]]; @throw e; } for (OFString *item in contents) { void *pool2 = objc_autoreleasePoolPush(); - OFString *sourcePath, *destinationPath; - - sourcePath = - [source stringByAppendingPathComponent: item]; - destinationPath = - [destination stringByAppendingPathComponent: item]; - - [self copyItemAtPath: sourcePath - toPath: destinationPath]; + OFURL *sourceURL, *destinationURL; + + sourceURL = + [source URLByAppendingPathComponent: item]; + destinationURL = + [destination URLByAppendingPathComponent: item]; + + [self copyItemAtURL: sourceURL + toURL: destinationURL]; objc_autoreleasePoolPop(pool2); } } else if ([type isEqual: of_file_type_regular]) { size_t pageSize = [OFSystemInfo pageSize]; - OFFile *sourceFile = nil; - OFFile *destinationFile = nil; + OFStream *sourceStream = nil; + OFStream *destinationStream = nil; char *buffer; if ((buffer = malloc(pageSize)) == NULL) @throw [OFOutOfMemoryException exceptionWithRequestedSize: pageSize]; @try { - sourceFile = [OFFile fileWithPath: source - mode: @"r"]; - destinationFile = [OFFile fileWithPath: destination - mode: @"w"]; + sourceStream = [[OFURLHandler handlerForURL: source] + openItemAtURL: source + mode: @"r"]; + destinationStream = [[OFURLHandler handlerForURL: + destination] openItemAtURL: destination + mode: @"w"]; - while (![sourceFile isAtEndOfStream]) { + while (![sourceStream isAtEndOfStream]) { size_t length; - length = [sourceFile readIntoBuffer: buffer - length: pageSize]; - [destinationFile writeBuffer: buffer - length: length]; + length = [sourceStream + readIntoBuffer: buffer + length: pageSize]; + [destinationStream writeBuffer: buffer + length: length]; } #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS of_file_attribute_key_t key = of_file_attribute_key_posix_permissions; @@ -569,11 +583,11 @@ of_file_attributes_t destinationAttributes = [OFDictionary dictionaryWithObject: permissions forKey: key]; [self setAttributes: destinationAttributes - ofItemAtPath: destination]; + ofItemAtURL: destination]; #endif } @catch (id e) { /* * Only convert exceptions to OFCopyItemFailedException * that have an errNo property. This covers all I/O @@ -580,59 +594,49 @@ * related exceptions from the operations used to copy * an item, all others should be left as is. */ if ([e respondsToSelector: @selector(errNo)]) @throw [OFCopyItemFailedException - exceptionWithSourcePath: source - destinationPath: destination - errNo: [e errNo]]; + exceptionWithSourceURL: source + destinationURL: destination + errNo: [e errNo]]; @throw e; } @finally { - [sourceFile close]; - [destinationFile close]; + [sourceStream close]; + [destinationStream close]; free(buffer); } #ifdef OF_FILE_MANAGER_SUPPORTS_SYMLINKS } else if ([type isEqual: of_file_type_symbolic_link]) { @try { - source = [attributes fileSymbolicLinkDestination]; + OFString *linkDestination = + [attributes fileSymbolicLinkDestination]; - [self createSymbolicLinkAtPath: destination - withDestinationPath: source]; + [self createSymbolicLinkAtURL: destination + withDestinationPath: linkDestination]; } @catch (id e) { /* * Only convert exceptions to OFCopyItemFailedException * that have an errNo property. This covers all I/O * related exceptions from the operations used to copy * an item, all others should be left as is. */ if ([e respondsToSelector: @selector(errNo)]) @throw [OFCopyItemFailedException - exceptionWithSourcePath: source - destinationPath: destination - errNo: [e errNo]]; + exceptionWithSourceURL: source + destinationURL: destination + errNo: [e errNo]]; @throw e; } #endif } else @throw [OFCopyItemFailedException - exceptionWithSourcePath: source - destinationPath: destination - errNo: EINVAL]; - - objc_autoreleasePoolPop(pool); -} - -- (void)copyItemAtURL: (OFURL *)source - toURL: (OFURL *)destination -{ - void *pool = objc_autoreleasePoolPush(); - - [self copyItemAtPath: [source fileSystemRepresentation] - toPath: [destination fileSystemRepresentation]]; + exceptionWithSourceURL: source + destinationURL: destination + errNo: EINVAL]; objc_autoreleasePoolPop(pool); } - (void)moveItemAtPath: (OFString *)source