Index: src/OFFileManager.m ================================================================== --- src/OFFileManager.m +++ src/OFFileManager.m @@ -40,11 +40,11 @@ #import "OFString.h" #import "OFSystemInfo.h" #import "OFURL.h" #import "OFURLHandler.h" -#import "OFChangeCurrentDirectoryPathFailedException.h" +#import "OFChangeCurrentDirectoryFailedException.h" #import "OFCopyItemFailedException.h" #import "OFCreateDirectoryFailedException.h" #import "OFGetCurrentDirectoryFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" @@ -513,11 +513,11 @@ default: errNo = 0; break; } - @throw [OFChangeCurrentDirectoryPathFailedException + @throw [OFChangeCurrentDirectoryFailedException exceptionWithPath: path errNo: errNo]; } oldLock = CurrentDir(lock); @@ -538,11 +538,11 @@ # endif status = chdir( [path cStringWithEncoding: [OFLocale encoding]]); if (status != 0) - @throw [OFChangeCurrentDirectoryPathFailedException + @throw [OFChangeCurrentDirectoryFailedException exceptionWithPath: path errNo: errno]; # endif } Index: src/ObjFW.h ================================================================== --- src/ObjFW.h +++ src/ObjFW.h @@ -148,11 +148,11 @@ #ifdef OF_HAVE_SOCKETS # import "OFAcceptFailedException.h" # import "OFAlreadyConnectedException.h" # import "OFBindFailedException.h" #endif -#import "OFChangeCurrentDirectoryPathFailedException.h" +#import "OFChangeCurrentDirectoryFailedException.h" #import "OFChecksumMismatchException.h" #ifdef OF_HAVE_THREADS # import "OFConditionBroadcastFailedException.h" # import "OFConditionSignalFailedException.h" # import "OFConditionStillWaitingException.h" Index: src/exceptions/Makefile ================================================================== --- src/exceptions/Makefile +++ src/exceptions/Makefile @@ -2,11 +2,10 @@ STATIC_PIC_LIB_NOINST = ${EXCEPTIONS_LIB_A} STATIC_LIB_NOINST = ${EXCEPTIONS_A} SRCS = OFAllocFailedException.m \ - OFChangeCurrentDirectoryPathFailedException.m \ OFChecksumMismatchException.m \ OFCopyItemFailedException.m \ OFCreateDirectoryFailedException.m \ OFCreateSymbolicLinkFailedException.m \ OFEnumerationMutationException.m \ @@ -49,11 +48,12 @@ ${USE_SRCS_FILES} \ ${USE_SRCS_PLUGINS} \ ${USE_SRCS_SOCKETS} \ ${USE_SRCS_THREADS} \ ${USE_SRCS_WINDOWS} -SRCS_FILES = OFGetCurrentDirectoryFailedException.m +SRCS_FILES = OFChangeCurrentDirectoryFailedException.m \ + OFGetCurrentDirectoryFailedException.m SRCS_PLUGINS = OFLoadPluginFailedException.m SRCS_SOCKETS = OFAcceptFailedException.m \ OFAlreadyConnectedException.m \ OFBindFailedException.m \ OFConnectionFailedException.m \ ADDED src/exceptions/OFChangeCurrentDirectoryFailedException.h Index: src/exceptions/OFChangeCurrentDirectoryFailedException.h ================================================================== --- src/exceptions/OFChangeCurrentDirectoryFailedException.h +++ src/exceptions/OFChangeCurrentDirectoryFailedException.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2008-2022 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. + */ + +#import "OFException.h" + +OF_ASSUME_NONNULL_BEGIN + +/** + * @class OFChangeCurrentDirectoryFailedException \ + * OFChangeCurrentDirectoryFailedException.h \ + * ObjFW/OFChangeCurrentDirectoryFailedException.h + * + * @brief An exception indicating that changing the current directory path + * failed. + */ +@interface OFChangeCurrentDirectoryFailedException: OFException +{ + OFString *_path; + int _errNo; + OF_RESERVE_IVARS(OFChangeCurrentDirectoryFailedException, 4) +} + +/** + * @brief The path of the directory to which the current path could not be + * changed. + */ +@property (readonly, nonatomic) OFString *path; + +/** + * @brief The errno of the error that occurred. + */ +@property (readonly, nonatomic) int errNo; + +/** + * @brief Creates a new, autoreleased change current directory path failed + * exception. + * + * @param path The path of the directory to which the current path could not be + * changed + * @param errNo The errno of the error that occurred + * @return A new, autoreleased change current directory path failed exception + */ ++ (instancetype)exceptionWithPath: (OFString *)path errNo: (int)errNo; + ++ (instancetype)exception OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated change directory failed exception. + * + * @param path The path of the directory to which the current path could not be + * changed + * @param errNo The errno of the error that occurred + * @return An initialized change current directory path failed exception + */ +- (instancetype)initWithPath: (OFString *)path + errNo: (int)errNo OF_DESIGNATED_INITIALIZER; + +- (instancetype)init OF_UNAVAILABLE; +@end + +OF_ASSUME_NONNULL_END ADDED src/exceptions/OFChangeCurrentDirectoryFailedException.m Index: src/exceptions/OFChangeCurrentDirectoryFailedException.m ================================================================== --- src/exceptions/OFChangeCurrentDirectoryFailedException.m +++ src/exceptions/OFChangeCurrentDirectoryFailedException.m @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2008-2022 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 "OFChangeCurrentDirectoryFailedException.h" +#import "OFString.h" + +@implementation OFChangeCurrentDirectoryFailedException +@synthesize path = _path, errNo = _errNo; + ++ (instancetype)exceptionWithPath: (OFString *)path errNo: (int)errNo +{ + return [[[self alloc] initWithPath: path errNo: errNo] autorelease]; +} + ++ (instancetype)exception +{ + OF_UNRECOGNIZED_SELECTOR +} + +- (instancetype)initWithPath: (OFString *)path errNo: (int)errNo +{ + self = [super init]; + + @try { + _path = [path copy]; + _errNo = errNo; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (instancetype)init +{ + OF_INVALID_INIT_METHOD +} + +- (void)dealloc +{ + [_path release]; + + [super dealloc]; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"Failed to change the current directory to %@: %@", + _path, OFStrError(_errNo)]; +} +@end DELETED src/exceptions/OFChangeCurrentDirectoryPathFailedException.h Index: src/exceptions/OFChangeCurrentDirectoryPathFailedException.h ================================================================== --- src/exceptions/OFChangeCurrentDirectoryPathFailedException.h +++ src/exceptions/OFChangeCurrentDirectoryPathFailedException.h @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2008-2022 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. - */ - -#import "OFException.h" - -OF_ASSUME_NONNULL_BEGIN - -/** - * @class OFChangeCurrentDirectoryPathFailedException \ - * OFChangeCurrentDirectoryPathFailedException.h \ - * ObjFW/OFChangeCurrentDirectoryPathFailedException.h - * - * @brief An exception indicating that changing the current directory path - * failed. - */ -@interface OFChangeCurrentDirectoryPathFailedException: OFException -{ - OFString *_path; - int _errNo; - OF_RESERVE_IVARS(OFChangeCurrentDirectoryPathFailedException, 4) -} - -/** - * @brief The path of the directory to which the current path could not be - * changed. - */ -@property (readonly, nonatomic) OFString *path; - -/** - * @brief The errno of the error that occurred. - */ -@property (readonly, nonatomic) int errNo; - -/** - * @brief Creates a new, autoreleased change current directory path failed - * exception. - * - * @param path The path of the directory to which the current path could not be - * changed - * @param errNo The errno of the error that occurred - * @return A new, autoreleased change current directory path failed exception - */ -+ (instancetype)exceptionWithPath: (OFString *)path errNo: (int)errNo; - -+ (instancetype)exception OF_UNAVAILABLE; - -/** - * @brief Initializes an already allocated change directory failed exception. - * - * @param path The path of the directory to which the current path could not be - * changed - * @param errNo The errno of the error that occurred - * @return An initialized change current directory path failed exception - */ -- (instancetype)initWithPath: (OFString *)path - errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - -- (instancetype)init OF_UNAVAILABLE; -@end - -OF_ASSUME_NONNULL_END DELETED src/exceptions/OFChangeCurrentDirectoryPathFailedException.m Index: src/exceptions/OFChangeCurrentDirectoryPathFailedException.m ================================================================== --- src/exceptions/OFChangeCurrentDirectoryPathFailedException.m +++ src/exceptions/OFChangeCurrentDirectoryPathFailedException.m @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2008-2022 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 "OFChangeCurrentDirectoryPathFailedException.h" -#import "OFString.h" - -@implementation OFChangeCurrentDirectoryPathFailedException -@synthesize path = _path, errNo = _errNo; - -+ (instancetype)exceptionWithPath: (OFString *)path errNo: (int)errNo -{ - return [[[self alloc] initWithPath: path errNo: errNo] autorelease]; -} - -+ (instancetype)exception -{ - OF_UNRECOGNIZED_SELECTOR -} - -- (instancetype)initWithPath: (OFString *)path errNo: (int)errNo -{ - self = [super init]; - - @try { - _path = [path copy]; - _errNo = errNo; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (instancetype)init -{ - OF_INVALID_INIT_METHOD -} - -- (void)dealloc -{ - [_path release]; - - [super dealloc]; -} - -- (OFString *)description -{ - return [OFString stringWithFormat: - @"Failed to change the current directory path to %@: %@", - _path, OFStrError(_errNo)]; -} -@end