Index: src/OFFileManager.m ================================================================== --- src/OFFileManager.m +++ src/OFFileManager.m @@ -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 Index: src/exceptions/OFCopyItemFailedException.h ================================================================== --- src/exceptions/OFCopyItemFailedException.h +++ src/exceptions/OFCopyItemFailedException.h @@ -16,31 +16,33 @@ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN +@class OFURL; + /*! * @class OFCopyItemFailedException \ * OFCopyItemFailedException.h ObjFW/OFCopyItemFailedException.h * * @brief An exception indicating that copying a item failed. */ @interface OFCopyItemFailedException: OFException { - OFString *_sourcePath, *_destinationPath; + OFURL *_sourceURL, *_destinationURL; int _errNo; } /*! * @brief The path of the source item. */ -@property (readonly, nonatomic) OFString *sourcePath; +@property (readonly, nonatomic) OFURL *sourceURL; /*! * @brief The destination path. */ -@property (readonly, nonatomic) OFString *destinationPath; +@property (readonly, nonatomic) OFURL *destinationURL; /*! * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; @@ -48,30 +50,30 @@ + (instancetype)exception OF_UNAVAILABLE; /*! * @brief Creates a new, autoreleased copy item failed exception. * - * @param sourcePath The original path - * @param destinationPath The new path + * @param sourceURL The original path + * @param destinationURL The new path * @param errNo The errno of the error that occurred * @return A new, autoreleased copy item failed exception */ -+ (instancetype)exceptionWithSourcePath: (OFString *)sourcePath - destinationPath: (OFString *)destinationPath - errNo: (int)errNo; ++ (instancetype)exceptionWithSourceURL: (OFURL *)sourceURL + destinationURL: (OFURL *)destinationURL + errNo: (int)errNo; - (instancetype)init OF_UNAVAILABLE; /*! * @brief Initializes an already allocated copy item failed exception. * - * @param sourcePath The original path - * @param destinationPath The new path + * @param sourceURL The original path + * @param destinationURL The new path * @param errNo The errno of the error that occurred * @return An initialized copy item failed exception */ -- (instancetype)initWithSourcePath: (OFString *)sourcePath - destinationPath: (OFString *)destinationPath - errNo: (int)errNo OF_DESIGNATED_INITIALIZER; +- (instancetype)initWithSourceURL: (OFURL *)sourceURL + destinationURL: (OFURL *)destinationURL + errNo: (int)errNo OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END Index: src/exceptions/OFCopyItemFailedException.m ================================================================== --- src/exceptions/OFCopyItemFailedException.m +++ src/exceptions/OFCopyItemFailedException.m @@ -18,41 +18,41 @@ #import "OFCopyItemFailedException.h" #import "OFString.h" @implementation OFCopyItemFailedException -@synthesize sourcePath = _sourcePath, destinationPath = _destinationPath; +@synthesize sourceURL = _sourceURL, destinationURL = _destinationURL; @synthesize errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } -+ (instancetype)exceptionWithSourcePath: (OFString *)sourcePath - destinationPath: (OFString *)destinationPath - errNo: (int)errNo ++ (instancetype)exceptionWithSourceURL: (OFURL *)sourceURL + destinationURL: (OFURL *)destinationURL + errNo: (int)errNo { - return [[[self alloc] initWithSourcePath: sourcePath - destinationPath: destinationPath - errNo: errNo] autorelease]; + return [[[self alloc] initWithSourceURL: sourceURL + destinationURL: destinationURL + errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } -- (instancetype)initWithSourcePath: (OFString *)sourcePath - destinationPath: (OFString *)destinationPath - errNo: (int)errNo +- (instancetype)initWithSourceURL: (OFURL *)sourceURL + destinationURL: (OFURL *)destinationURL + errNo: (int)errNo { self = [super init]; @try { - _sourcePath = [sourcePath copy]; - _destinationPath = [destinationPath copy]; + _sourceURL = [sourceURL copy]; + _destinationURL = [destinationURL copy]; _errNo = errNo; } @catch (id e) { [self release]; @throw e; } @@ -60,17 +60,17 @@ return self; } - (void)dealloc { - [_sourcePath release]; - [_destinationPath release]; + [_sourceURL release]; + [_destinationURL release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to copy item %@ to %@: %@", - _sourcePath, _destinationPath, of_strerror(_errNo)]; + _sourceURL, _destinationURL, of_strerror(_errNo)]; } @end