Index: ObjFW.xcodeproj/project.pbxproj ================================================================== --- ObjFW.xcodeproj/project.pbxproj +++ ObjFW.xcodeproj/project.pbxproj @@ -112,12 +112,10 @@ 4B23CA941338121C0047A1D9 /* TestPlugin.bundle in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4B23CA8A133811610047A1D9 /* TestPlugin.bundle */; }; 4B29BC3F133AC4E80004B236 /* OFCreateDirectoryFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B29BC37133AC4E80004B236 /* OFCreateDirectoryFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B29BC40133AC4E80004B236 /* OFCreateDirectoryFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B29BC38133AC4E80004B236 /* OFCreateDirectoryFailedException.m */; }; 4B29BC41133AC4E80004B236 /* OFSeekFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B29BC39133AC4E80004B236 /* OFSeekFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B29BC42133AC4E80004B236 /* OFSeekFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B29BC3A133AC4E80004B236 /* OFSeekFailedException.m */; }; - 4B29BC4E133AC7DD0004B236 /* OFCopyFileFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B29BC46133AC7DB0004B236 /* OFCopyFileFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 4B29BC4F133AC7DD0004B236 /* OFCopyFileFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B29BC47133AC7DB0004B236 /* OFCopyFileFailedException.m */; }; 4B29BC58133AC8540004B236 /* OFConditionBroadcastFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B8B1701133A3B8E007CD8B3 /* OFConditionBroadcastFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B29BC59133AC8540004B236 /* OFConditionSignalFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B8B1703133A3B8E007CD8B3 /* OFConditionSignalFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B29BC5A133AC8540004B236 /* OFConditionWaitFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B8B1705133A3B8E007CD8B3 /* OFConditionWaitFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B29BC61133AC9CB0004B236 /* OFLinkFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B29BC5D133AC9C40004B236 /* OFLinkFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B29BC62133AC9CB0004B236 /* OFLinkFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B29BC5E133AC9C40004B236 /* OFLinkFailedException.m */; }; @@ -264,10 +262,12 @@ 4B55A116133AC24600B58A93 /* OFWriteFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B55A110133AC24500B58A93 /* OFWriteFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B55A117133AC24600B58A93 /* OFWriteFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B55A111133AC24600B58A93 /* OFWriteFailedException.m */; }; 4B5C112F17E9AB3E003C917F /* forwarding.S in Sources */ = {isa = PBXBuildFile; fileRef = 4B5C112C17E9AAED003C917F /* forwarding.S */; }; 4B5CF8F914940BD2007AA324 /* OFString+JSONValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B5CF8F614940BD2007AA324 /* OFString+JSONValue.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B5CF8FA14940BD2007AA324 /* OFString+JSONValue.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B5CF8F714940BD2007AA324 /* OFString+JSONValue.m */; }; + 4B62ED1518566FCA0004E0E3 /* OFCopyItemFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B62ED1318566FCA0004E0E3 /* OFCopyItemFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4B62ED1618566FCA0004E0E3 /* OFCopyItemFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B62ED1418566FCA0004E0E3 /* OFCopyItemFailedException.m */; }; 4B64D6EF1425381E007BDFB1 /* OFStreamObserver_poll.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B64D6EB1425381E007BDFB1 /* OFStreamObserver_poll.h */; }; 4B64D6F01425381E007BDFB1 /* OFStreamObserver_poll.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B64D6EC1425381E007BDFB1 /* OFStreamObserver_poll.m */; }; 4B64D6F11425381E007BDFB1 /* OFStreamObserver_select.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B64D6ED1425381E007BDFB1 /* OFStreamObserver_select.h */; }; 4B64D6F21425381E007BDFB1 /* OFStreamObserver_select.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B64D6EE1425381E007BDFB1 /* OFStreamObserver_select.m */; }; 4B66B636182ADC45000A69E3 /* OFDeflate64Stream.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B66B634182ADC45000A69E3 /* OFDeflate64Stream.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -567,12 +567,10 @@ 4B23CA8A133811610047A1D9 /* TestPlugin.bundle */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = TestPlugin.bundle; sourceTree = BUILT_PRODUCTS_DIR; }; 4B29BC37133AC4E80004B236 /* OFCreateDirectoryFailedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFCreateDirectoryFailedException.h; path = src/exceptions/OFCreateDirectoryFailedException.h; sourceTree = ""; }; 4B29BC38133AC4E80004B236 /* OFCreateDirectoryFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFCreateDirectoryFailedException.m; path = src/exceptions/OFCreateDirectoryFailedException.m; sourceTree = ""; }; 4B29BC39133AC4E80004B236 /* OFSeekFailedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFSeekFailedException.h; path = src/exceptions/OFSeekFailedException.h; sourceTree = ""; }; 4B29BC3A133AC4E80004B236 /* OFSeekFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFSeekFailedException.m; path = src/exceptions/OFSeekFailedException.m; sourceTree = ""; }; - 4B29BC46133AC7DB0004B236 /* OFCopyFileFailedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFCopyFileFailedException.h; path = src/exceptions/OFCopyFileFailedException.h; sourceTree = ""; }; - 4B29BC47133AC7DB0004B236 /* OFCopyFileFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFCopyFileFailedException.m; path = src/exceptions/OFCopyFileFailedException.m; sourceTree = ""; }; 4B29BC5D133AC9C40004B236 /* OFLinkFailedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFLinkFailedException.h; path = src/exceptions/OFLinkFailedException.h; sourceTree = ""; }; 4B29BC5E133AC9C40004B236 /* OFLinkFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFLinkFailedException.m; path = src/exceptions/OFLinkFailedException.m; sourceTree = ""; }; 4B2B3E73140D430500EC2F7C /* OFArray_adjacent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFArray_adjacent.h; path = src/OFArray_adjacent.h; sourceTree = ""; }; 4B2B3E74140D430500EC2F7C /* OFArray_adjacent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFArray_adjacent.m; path = src/OFArray_adjacent.m; sourceTree = ""; }; 4B2B3E75140D430500EC2F7C /* OFDictionary_hashtable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFDictionary_hashtable.h; path = src/OFDictionary_hashtable.h; sourceTree = ""; }; @@ -637,10 +635,12 @@ 4B5C112B17E9AAED003C917F /* apple-forwarding-x86_64.S */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; name = "apple-forwarding-x86_64.S"; path = "src/forwarding/apple-forwarding-x86_64.S"; sourceTree = ""; }; 4B5C112C17E9AAED003C917F /* forwarding.S */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; name = forwarding.S; path = src/forwarding/forwarding.S; sourceTree = ""; }; 4B5C112E17E9AB0C003C917F /* Makefile */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.make; name = Makefile; path = src/forwarding/Makefile; sourceTree = ""; }; 4B5CF8F614940BD2007AA324 /* OFString+JSONValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "OFString+JSONValue.h"; path = "src/OFString+JSONValue.h"; sourceTree = ""; }; 4B5CF8F714940BD2007AA324 /* OFString+JSONValue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "OFString+JSONValue.m"; path = "src/OFString+JSONValue.m"; sourceTree = ""; }; + 4B62ED1318566FCA0004E0E3 /* OFCopyItemFailedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFCopyItemFailedException.h; path = src/exceptions/OFCopyItemFailedException.h; sourceTree = ""; }; + 4B62ED1418566FCA0004E0E3 /* OFCopyItemFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFCopyItemFailedException.m; path = src/exceptions/OFCopyItemFailedException.m; sourceTree = ""; }; 4B64D6EB1425381E007BDFB1 /* OFStreamObserver_poll.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFStreamObserver_poll.h; path = src/OFStreamObserver_poll.h; sourceTree = ""; }; 4B64D6EC1425381E007BDFB1 /* OFStreamObserver_poll.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFStreamObserver_poll.m; path = src/OFStreamObserver_poll.m; sourceTree = ""; }; 4B64D6ED1425381E007BDFB1 /* OFStreamObserver_select.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFStreamObserver_select.h; path = src/OFStreamObserver_select.h; sourceTree = ""; }; 4B64D6EE1425381E007BDFB1 /* OFStreamObserver_select.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFStreamObserver_select.m; path = src/OFStreamObserver_select.m; sourceTree = ""; }; 4B66B634182ADC45000A69E3 /* OFDeflate64Stream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFDeflate64Stream.h; path = src/OFDeflate64Stream.h; sourceTree = ""; }; @@ -953,12 +953,12 @@ 4B7FF3B3133CED6100000324 /* OFConditionStillWaitingException.m */, 4B8B1705133A3B8E007CD8B3 /* OFConditionWaitFailedException.h */, 4B8B1706133A3B8E007CD8B3 /* OFConditionWaitFailedException.m */, 4B90B79A133AD87D00BD33CB /* OFConnectionFailedException.h */, 4B90B79B133AD87D00BD33CB /* OFConnectionFailedException.m */, - 4B29BC46133AC7DB0004B236 /* OFCopyFileFailedException.h */, - 4B29BC47133AC7DB0004B236 /* OFCopyFileFailedException.m */, + 4B62ED1318566FCA0004E0E3 /* OFCopyItemFailedException.h */, + 4B62ED1418566FCA0004E0E3 /* OFCopyItemFailedException.m */, 4B29BC37133AC4E80004B236 /* OFCreateDirectoryFailedException.h */, 4B29BC38133AC4E80004B236 /* OFCreateDirectoryFailedException.m */, 4B067FB5177BA6F900B8CFDA /* OFCreateSymbolicLinkFailedException.h */, 4B067FB6177BA6F900B8CFDA /* OFCreateSymbolicLinkFailedException.m */, 4B17FF85133A2E7A003E6DCD /* OFEnumerationMutationException.h */, @@ -1567,11 +1567,11 @@ 4B29BC58133AC8540004B236 /* OFConditionBroadcastFailedException.h in Headers */, 4B29BC59133AC8540004B236 /* OFConditionSignalFailedException.h in Headers */, 4B7FF3B4133CED6200000324 /* OFConditionStillWaitingException.h in Headers */, 4B29BC5A133AC8540004B236 /* OFConditionWaitFailedException.h in Headers */, 4B90B7A4133AD87D00BD33CB /* OFConnectionFailedException.h in Headers */, - 4B29BC4E133AC7DD0004B236 /* OFCopyFileFailedException.h in Headers */, + 4B62ED1518566FCA0004E0E3 /* OFCopyItemFailedException.h in Headers */, 4B29BC3F133AC4E80004B236 /* OFCreateDirectoryFailedException.h in Headers */, 4B067FC1177BA6F900B8CFDA /* OFCreateSymbolicLinkFailedException.h in Headers */, 4B17FF87133A2E7B003E6DCD /* OFEnumerationMutationException.h in Headers */, 4B8B16FE133A3B84007CD8B3 /* OFHashAlreadyCalculatedException.h in Headers */, 4B17FFAD133A3591003E6DCD /* OFHTTPRequestFailedException.h in Headers */, @@ -1933,11 +1933,11 @@ 4B8B170D133A3C11007CD8B3 /* OFConditionBroadcastFailedException.m in Sources */, 4B8B170E133A3C11007CD8B3 /* OFConditionSignalFailedException.m in Sources */, 4B7FF3B5133CED6200000324 /* OFConditionStillWaitingException.m in Sources */, 4B8B170F133A3C11007CD8B3 /* OFConditionWaitFailedException.m in Sources */, 4B90B7A5133AD87D00BD33CB /* OFConnectionFailedException.m in Sources */, - 4B29BC4F133AC7DD0004B236 /* OFCopyFileFailedException.m in Sources */, + 4B62ED1618566FCA0004E0E3 /* OFCopyItemFailedException.m in Sources */, 4B29BC40133AC4E80004B236 /* OFCreateDirectoryFailedException.m in Sources */, 4B067FC2177BA6F900B8CFDA /* OFCreateSymbolicLinkFailedException.m in Sources */, 4B17FF88133A2E7B003E6DCD /* OFEnumerationMutationException.m in Sources */, 4B17FF73133A2A76003E6DCD /* OFException.m in Sources */, 4B8B16FF133A3B84007CD8B3 /* OFHashAlreadyCalculatedException.m in Sources */, Index: src/OFFile.h ================================================================== --- src/OFFile.h +++ src/OFFile.h @@ -176,16 +176,19 @@ owner: (OFString*)owner group: (OFString*)group; #endif /*! - * @brief Copies a file. + * @brief Copies a file, directory or symlink (if supported by the OS). + * + * If an item already exists, it is replaced. This is also the case if a + * directory is copied and an item already exists in the destination directory. * - * @param source The file to copy + * @param source The file, directory or symlink to copy * @param destination The destination path */ -+ (void)copyFileAtPath: (OFString*)source ++ (void)copyItemAtPath: (OFString*)source toPath: (OFString*)destination; /*! * @brief Renames an item. * Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -58,10 +58,11 @@ #import "OFSystemInfo.h" #import "OFChangeCurrentDirectoryPathFailedException.h" #import "OFChangeOwnerFailedException.h" #import "OFChangePermissionsFailedException.h" +#import "OFCopyItemFailedException.h" #import "OFCreateDirectoryFailedException.h" #import "OFCreateSymbolicLinkFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFLinkFailedException.h" @@ -527,19 +528,15 @@ owner: owner group: group]; } #endif -+ (void)copyFileAtPath: (OFString*)source ++ (void)copyItemAtPath: (OFString*)source toPath: (OFString*)destination { void *pool; - bool override; - OFFile *sourceFile = nil; - OFFile *destinationFile = nil; - char *buffer; - size_t pageSize; + struct stat s; if (source == nil || destination == nil) @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); @@ -548,48 +545,122 @@ OFArray *components = [OFArray arrayWithObjects: destination, [source lastPathComponent], nil]; destination = [OFString pathWithComponents: components]; } - override = [self fileExistsAtPath: destination]; - pageSize = [OFSystemInfo pageSize]; - - if ((buffer = malloc(pageSize)) == NULL) - @throw [OFOutOfMemoryException - exceptionWithRequestedSize: pageSize]; - - @try { - sourceFile = [OFFile fileWithPath: source - mode: @"rb"]; - destinationFile = [OFFile fileWithPath: destination - mode: @"wb"]; - - while (![sourceFile isAtEndOfStream]) { - size_t length; - - length = [sourceFile readIntoBuffer: buffer - length: pageSize]; - [destinationFile writeBuffer: buffer - length: length]; - } + if (lstat([source cStringWithEncoding: OF_STRING_ENCODING_NATIVE], &s)) + @throw [OFCopyItemFailedException + exceptionWithSourcePath: source + destinationPath: destination]; + + if (S_ISREG(s.st_mode)) { +#ifdef OF_HAVE_CHMOD + bool override = [self fileExistsAtPath: destination]; +#endif + size_t pageSize = [OFSystemInfo pageSize]; + OFFile *sourceFile = nil; + OFFile *destinationFile = nil; + char *buffer; + + if ((buffer = malloc(pageSize)) == NULL) + @throw [OFOutOfMemoryException + exceptionWithRequestedSize: pageSize]; + + @try { +#ifdef OF_HAVE_SYMLINK + if ([OFFile symbolicLinkExistsAtPath: destination]) + [OFFile removeItemAtPath: destination]; +#endif + + sourceFile = [OFFile fileWithPath: source + mode: @"rb"]; + destinationFile = [OFFile fileWithPath: destination + mode: @"wb"]; + + while (![sourceFile isAtEndOfStream]) { + size_t length; + + length = [sourceFile readIntoBuffer: buffer + length: pageSize]; + [destinationFile writeBuffer: buffer + length: length]; + } #ifdef OF_HAVE_CHMOD - if (!override) { - struct stat s; - - if (fstat(sourceFile->_fd, &s) == 0) + if (!override) [self changePermissionsOfItemAtPath: destination permissions: s.st_mode]; +#endif + } @catch (id e) { + @throw [OFCopyItemFailedException + exceptionWithSourcePath: source + destinationPath: destination]; + } @finally { + [sourceFile close]; + [destinationFile close]; + free(buffer); + } + } else if (S_ISDIR(s.st_mode)) { + OFArray *contents; + OFEnumerator *enumerator; + OFString *item; + + @try { + if (![OFFile directoryExistsAtPath: destination]) + [OFFile createDirectoryAtPath: destination]; + +#ifdef OF_HAVE_CHMOD + [OFFile changePermissionsOfItemAtPath: destination + permissions: s.st_mode]; +#endif + + contents = [OFFile contentsOfDirectoryAtPath: source]; + } @catch (id e) { + @throw [OFCopyItemFailedException + exceptionWithSourcePath: source + destinationPath: destination]; + } + + enumerator = [contents objectEnumerator]; + while ((item = [enumerator nextObject]) != nil) { + OFArray *components; + OFString *sourcePath, *destinationPath; + + components = [OFArray arrayWithObjects: + source, item, nil]; + sourcePath = [OFString pathWithComponents: components]; + + components = [OFArray arrayWithObjects: + destination, item, nil]; + destinationPath = [OFString + pathWithComponents: components]; + + [OFFile copyItemAtPath: sourcePath + toPath: destinationPath]; } -#else - (void)override; +#ifdef OF_HAVE_SYMLINK + } else if (S_ISLNK(s.st_mode)) { + @try { + if ([OFFile symbolicLinkExistsAtPath: destination] || + [OFFile fileExistsAtPath: destination]) + [OFFile removeItemAtPath: destination]; + + source = [OFFile + destinationOfSymbolicLinkAtPath: source]; + + [OFFile createSymbolicLinkAtPath: destination + withDestinationPath: source]; + } @catch (id e) { + @throw [OFCopyItemFailedException + exceptionWithSourcePath: source + destinationPath: destination]; + } #endif - } @finally { - [sourceFile close]; - [destinationFile close]; - free(buffer); - } + } else + @throw [OFCopyItemFailedException + exceptionWithSourcePath: source + destinationPath: destination]; objc_autoreleasePoolPop(pool); } + (void)renameItemAtPath: (OFString*)source Index: src/ObjFW.h ================================================================== --- src/ObjFW.h +++ src/ObjFW.h @@ -106,11 +106,11 @@ # import "OFConditionWaitFailedException.h" #endif #ifdef OF_HAVE_SOCKETS # import "OFConnectionFailedException.h" #endif -#import "OFCopyFileFailedException.h" +#import "OFCopyItemFailedException.h" #import "OFCreateDirectoryFailedException.h" #import "OFCreateSymbolicLinkFailedException.h" #import "OFEnumerationMutationException.h" #import "OFHashAlreadyCalculatedException.h" #ifdef OF_HAVE_SOCKETS Index: src/exceptions/Makefile ================================================================== --- src/exceptions/Makefile +++ src/exceptions/Makefile @@ -6,11 +6,11 @@ SRCS = OFAllocFailedException.m \ OFChangeCurrentDirectoryPathFailedException.m \ OFChangeOwnerFailedException.m \ OFChangePermissionsFailedException.m \ OFChecksumFailedException.m \ - OFCopyFileFailedException.m \ + OFCopyItemFailedException.m \ OFCreateDirectoryFailedException.m \ OFCreateSymbolicLinkFailedException.m \ OFEnumerationMutationException.m \ OFException.m \ OFHashAlreadyCalculatedException.m \ DELETED src/exceptions/OFCopyFileFailedException.h Index: src/exceptions/OFCopyFileFailedException.h ================================================================== --- src/exceptions/OFCopyFileFailedException.h +++ src/exceptions/OFCopyFileFailedException.h @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include - -#import "OFException.h" - -/*! - * @brief An exception indicating that copying a file failed. - */ -@interface OFCopyFileFailedException: OFException -{ - OFString *_sourcePath, *_destinationPath; - int _errNo; -} - -#ifdef OF_HAVE_PROPERTIES -@property (readonly, copy) OFString *sourcePath; -@property (readonly, copy) OFString *destinationPath; -@property (readonly) int errNo; -#endif - -/*! - * @brief Creates a new, autoreleased copy file failed exception. - * - * @param sourcePath The original path - * @param destinationPath The new path - * @return A new, autoreleased copy file failed exception - */ -+ (instancetype)exceptionWithSourcePath: (OFString*)sourcePath - destinationPath: (OFString*)destinationPath; - -/*! - * @brief Initializes an already allocated copy file failed exception. - * - * @param sourcePath The original path - * @param destinationPath The new path - * @return An initialized copy file failed exception - */ -- initWithSourcePath: (OFString*)sourcePath - destinationPath: (OFString*)destinationPath; - -/*! - * @brief Returns the path of the source file. - * - * @return The path of the source file - */ -- (OFString*)sourcePath; - -/*! - * @brief Returns the destination path. - * - * @return The destination path - */ -- (OFString*)destinationPath; - -/*! - * @brief Returns the errno from when the exception was created. - * - * @return The errno from when the exception was created - */ -- (int)errNo; -@end DELETED src/exceptions/OFCopyFileFailedException.m Index: src/exceptions/OFCopyFileFailedException.m ================================================================== --- src/exceptions/OFCopyFileFailedException.m +++ src/exceptions/OFCopyFileFailedException.m @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#import "OFCopyFileFailedException.h" -#import "OFString.h" - -#import "common.h" -#import "macros.h" - -@implementation OFCopyFileFailedException -+ (instancetype)exceptionWithSourcePath: (OFString*)sourcePath - destinationPath: (OFString*)destinationPath -{ - return [[[self alloc] initWithSourcePath: sourcePath - destinationPath: destinationPath] autorelease]; -} - -- init -{ - OF_INVALID_INIT_METHOD -} - -- initWithSourcePath: (OFString*)sourcePath - destinationPath: (OFString*)destinationPath -{ - self = [super init]; - - @try { - _sourcePath = [sourcePath copy]; - _destinationPath = [destinationPath copy]; - _errNo = GET_ERRNO; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (void)dealloc -{ - [_sourcePath release]; - [_destinationPath release]; - - [super dealloc]; -} - -- (OFString*)description -{ - return [OFString stringWithFormat: - @"Failed to copy file %@ to %@! " ERRFMT, _sourcePath, - _destinationPath, ERRPARAM]; -} - -- (OFString*)sourcePath -{ - OF_GETTER(_sourcePath, true) -} - -- (OFString*)destinationPath -{ - OF_GETTER(_destinationPath, true) -} - -- (int)errNo -{ - return _errNo; -} -@end ADDED src/exceptions/OFCopyItemFailedException.h Index: src/exceptions/OFCopyItemFailedException.h ================================================================== --- src/exceptions/OFCopyItemFailedException.h +++ src/exceptions/OFCopyItemFailedException.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include + +#import "OFException.h" + +/*! + * @brief An exception indicating that copying a item failed. + */ +@interface OFCopyItemFailedException: OFException +{ + OFString *_sourcePath, *_destinationPath; + int _errNo; +} + +#ifdef OF_HAVE_PROPERTIES +@property (readonly, copy) OFString *sourcePath; +@property (readonly, copy) OFString *destinationPath; +@property (readonly) int errNo; +#endif + +/*! + * @brief Creates a new, autoreleased copy item failed exception. + * + * @param sourcePath The original path + * @param destinationPath The new path + * @return A new, autoreleased copy item failed exception + */ ++ (instancetype)exceptionWithSourcePath: (OFString*)sourcePath + destinationPath: (OFString*)destinationPath; + +/*! + * @brief Initializes an already allocated copy item failed exception. + * + * @param sourcePath The original path + * @param destinationPath The new path + * @return An initialized copy item failed exception + */ +- initWithSourcePath: (OFString*)sourcePath + destinationPath: (OFString*)destinationPath; + +/*! + * @brief Returns the path of the source item. + * + * @return The path of the source item + */ +- (OFString*)sourcePath; + +/*! + * @brief Returns the destination path. + * + * @return The destination path + */ +- (OFString*)destinationPath; + +/*! + * @brief Returns the errno from when the exception was created. + * + * @return The errno from when the exception was created + */ +- (int)errNo; +@end ADDED src/exceptions/OFCopyItemFailedException.m Index: src/exceptions/OFCopyItemFailedException.m ================================================================== --- src/exceptions/OFCopyItemFailedException.m +++ src/exceptions/OFCopyItemFailedException.m @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFCopyItemFailedException.h" +#import "OFString.h" + +#import "common.h" +#import "macros.h" + +@implementation OFCopyItemFailedException ++ (instancetype)exceptionWithSourcePath: (OFString*)sourcePath + destinationPath: (OFString*)destinationPath +{ + return [[[self alloc] initWithSourcePath: sourcePath + destinationPath: destinationPath] autorelease]; +} + +- init +{ + OF_INVALID_INIT_METHOD +} + +- initWithSourcePath: (OFString*)sourcePath + destinationPath: (OFString*)destinationPath +{ + self = [super init]; + + @try { + _sourcePath = [sourcePath copy]; + _destinationPath = [destinationPath copy]; + _errNo = GET_ERRNO; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [_sourcePath release]; + [_destinationPath release]; + + [super dealloc]; +} + +- (OFString*)description +{ + return [OFString stringWithFormat: + @"Failed to copy item %@ to %@! " ERRFMT, _sourcePath, + _destinationPath, ERRPARAM]; +} + +- (OFString*)sourcePath +{ + OF_GETTER(_sourcePath, true) +} + +- (OFString*)destinationPath +{ + OF_GETTER(_destinationPath, true) +} + +- (int)errNo +{ + return _errNo; +} +@end