Index: src/OFFileManager.m ================================================================== --- src/OFFileManager.m +++ src/OFFileManager.m @@ -51,11 +51,11 @@ #import "OFMoveItemFailedException.h" #import "OFNotImplementedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFRemoveItemFailedException.h" -#import "OFRetrieveItemAttributesFailedException.h" +#import "OFGetItemAttributesFailedException.h" #import "OFUndefinedKeyException.h" #import "OFUnsupportedProtocolException.h" #ifdef OF_WINDOWS # include @@ -591,11 +591,11 @@ destinationURL: destination errNo: EEXIST]; @try { attributes = [self attributesOfItemAtURL: source]; - } @catch (OFRetrieveItemAttributesFailedException *e) { + } @catch (OFGetItemAttributesFailedException *e) { @throw [OFCopyItemFailedException exceptionWithSourceURL: source destinationURL: destination errNo: e.errNo]; } Index: src/OFFileURLHandler.m ================================================================== --- src/OFFileURLHandler.m +++ src/OFFileURLHandler.m @@ -55,20 +55,20 @@ # import "OFMutex.h" #endif #import "OFCreateDirectoryFailedException.h" #import "OFCreateSymbolicLinkFailedException.h" +#import "OFGetItemAttributesFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFLinkItemFailedException.h" #import "OFMoveItemFailedException.h" #import "OFNotImplementedException.h" #import "OFOpenItemFailedException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFRemoveItemFailedException.h" -#import "OFRetrieveItemAttributesFailedException.h" #import "OFSetItemAttributesFailedException.h" #ifdef OF_WINDOWS # include # include @@ -140,11 +140,11 @@ return (double)((int64_t)filetime->dwHighDateTime << 32 | filetime->dwLowDateTime) / 10000000.0 - 11644473600.0; } static int -retrieveError(void) +lastError(void) { switch (GetLastError()) { case ERROR_FILE_NOT_FOUND: case ERROR_PATH_NOT_FOUND: case ERROR_NO_MORE_FILES: @@ -161,11 +161,11 @@ } #endif #ifdef OF_AMIGAOS static int -retrieveError(void) +lastError(void) { switch (IoErr()) { case ERROR_DELETE_PROTECTED: case ERROR_READ_PROTECTED: case ERROR_WRITE_PROTECTED: @@ -209,11 +209,11 @@ success = GetFileAttributesExA( [path cStringWithEncoding: [OFLocale encoding]], GetFileExInfoStandard, &data); if (!success) - return retrieveError(); + return lastError(); buffer->st_size = (uint64_t)data.nFileSizeHigh << 32 | data.nFileSizeLow; if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) @@ -226,11 +226,11 @@ WIN32_FIND_DATAW findData; HANDLE findHandle; if ((findHandle = FindFirstFileW(path.UTF16String, &findData)) == INVALID_HANDLE_VALUE) - return retrieveError(); + return lastError(); @try { if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)) /* Race? Indicate to try again. */ @@ -266,20 +266,20 @@ struct Locale *locale; struct DateStamp *date; if ((lock = Lock([path cStringWithEncoding: [OFLocale encoding]], SHARED_LOCK)) == 0) - return retrieveError(); + return lastError(); # if defined(OF_MORPHOS) if (!Examine64(lock, &fib, TAG_DONE)) { # elif defined(OF_AMIGAOS4) if ((ed = ExamineObjectTags(EX_FileLockInput, lock, TAG_END)) == NULL) { # else if (!Examine(lock, &fib)) { # endif - int error = retrieveError(); + int error = lastError(); UnLock(lock); return error; } UnLock(lock); @@ -468,11 +468,11 @@ length = readlink([path cStringWithEncoding: encoding], destinationC, PATH_MAX); if (length < 0) - @throw [OFRetrieveItemAttributesFailedException + @throw [OFGetItemAttributesFailedException exceptionWithURL: URL errNo: errno]; destination = [OFString stringWithCString: destinationC encoding: encoding @@ -488,13 +488,13 @@ return; if ((handle = CreateFileW(path.UTF16String, 0, (FILE_SHARE_READ | FILE_SHARE_WRITE), NULL, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT, NULL)) == INVALID_HANDLE_VALUE) - @throw [OFRetrieveItemAttributesFailedException + @throw [OFGetItemAttributesFailedException exceptionWithURL: URL - errNo: retrieveError()]; + errNo: lastError()]; @try { union { char bytes[MAXIMUM_REPARSE_DATA_BUFFER_SIZE]; REPARSE_DATA_BUFFER data; @@ -503,18 +503,18 @@ wchar_t *tmp; if (!DeviceIoControl(handle, FSCTL_GET_REPARSE_POINT, NULL, 0, buffer.bytes, MAXIMUM_REPARSE_DATA_BUFFER_SIZE, &size, NULL)) - @throw [OFRetrieveItemAttributesFailedException + @throw [OFGetItemAttributesFailedException exceptionWithURL: URL - errNo: retrieveError()]; + errNo: lastError()]; if (buffer.data.ReparseTag != IO_REPARSE_TAG_SYMLINK) - @throw [OFRetrieveItemAttributesFailedException + @throw [OFGetItemAttributesFailedException exceptionWithURL: URL - errNo: retrieveError()]; + errNo: lastError()]; # define slrb buffer.data.SymbolicLinkReparseBuffer tmp = slrb.PathBuffer + (slrb.SubstituteNameOffset / sizeof(wchar_t)); @@ -614,11 +614,11 @@ @throw [OFInvalidArgumentException exception]; path = URL.fileSystemRepresentation; if ((error = lstatWrapper(path, &s)) != 0) - @throw [OFRetrieveItemAttributesFailedException + @throw [OFGetItemAttributesFailedException exceptionWithURL: URL errNo: error]; if (s.st_size < 0) @throw [OFOutOfRangeException exception]; @@ -729,11 +729,11 @@ # endif @throw [OFSetItemAttributesFailedException exceptionWithURL: URL attributes: attributes failedAttribute: attributeKey - errNo: retrieveError()]; + errNo: lastError()]; #else OFTimeInterval lastAccessTime = lastAccessDate.timeIntervalSince1970; OFTimeInterval modificationTime = modificationDate.timeIntervalSince1970; struct timeval times[2] = { @@ -987,11 +987,11 @@ if ((lock = CreateDir( [path cStringWithEncoding: [OFLocale encoding]])) == 0) @throw [OFCreateDirectoryFailedException exceptionWithURL: URL - errNo: retrieveError()]; + errNo: lastError()]; UnLock(lock); #else if (mkdir([path cStringWithEncoding: [OFLocale encoding]], 0777) != 0) @throw [OFCreateDirectoryFailedException @@ -1027,11 +1027,11 @@ if ((handle = FindFirstFileW(path.UTF16String, &fd)) == INVALID_HANDLE_VALUE) @throw [OFOpenItemFailedException exceptionWithURL: URL mode: nil - errNo: retrieveError()]; + errNo: lastError()]; @try { do { OFString *file; @@ -1051,11 +1051,11 @@ if (GetLastError() != ERROR_NO_MORE_FILES) @throw [OFReadFailedException exceptionWithObject: self requestedLength: 0 - errNo: retrieveError()]; + errNo: lastError()]; } @finally { FindClose(handle); } } else { OFStringEncoding encoding = [OFLocale encoding]; @@ -1065,11 +1065,11 @@ [path cStringWithEncoding: encoding], &fd)) == INVALID_HANDLE_VALUE) @throw [OFOpenItemFailedException exceptionWithURL: URL mode: nil - errNo: retrieveError()]; + errNo: lastError()]; @try { do { OFString *file; @@ -1090,11 +1090,11 @@ if (GetLastError() != ERROR_NO_MORE_FILES) @throw [OFReadFailedException exceptionWithObject: self requestedLength: 0 - errNo: retrieveError()]; + errNo: lastError()]; } @finally { FindClose(handle); } } #elif defined(OF_AMIGAOS) @@ -1104,11 +1104,11 @@ if ((lock = Lock([path cStringWithEncoding: encoding], SHARED_LOCK)) == 0) @throw [OFOpenItemFailedException exceptionWithURL: URL mode: nil - errNo: retrieveError()]; + errNo: lastError()]; @try { # ifdef OF_AMIGAOS4 struct ExamineData *ed; APTR context; @@ -1117,11 +1117,11 @@ EX_DoCurrentDir, TRUE, EX_DataFields, EXF_NAME, TAG_END)) == NULL) @throw [OFOpenItemFailedException exceptionWithURL: URL mode: nil - errNo: retrieveError()]; + errNo: lastError()]; @try { while ((ed = ExamineDir(context)) != NULL) { OFString *file = [[OFString alloc] initWithCString: ed->Name @@ -1142,11 +1142,11 @@ if (!Examine(lock, &fib)) @throw [OFOpenItemFailedException exceptionWithURL: URL mode: nil - errNo: retrieveError()]; + errNo: lastError()]; while (ExNext(lock, &fib)) { OFString *file = [[OFString alloc] initWithCString: fib.fib_FileName encoding: encoding]; @@ -1161,11 +1161,11 @@ if (IoErr() != ERROR_NO_MORE_ENTRIES) @throw [OFReadFailedException exceptionWithObject: self requestedLength: 0 - errNo: retrieveError()]; + errNo: lastError()]; } @finally { UnLock(lock); } #else OFStringEncoding encoding = [OFLocale encoding]; @@ -1325,11 +1325,11 @@ #ifdef OF_AMIGAOS if (!DeleteFile([path cStringWithEncoding: [OFLocale encoding]])) @throw [OFRemoveItemFailedException exceptionWithURL: URL - errNo: retrieveError()]; + errNo: lastError()]; #endif objc_autoreleasePoolPop(pool); } @@ -1366,11 +1366,11 @@ if (!createHardLinkWFuncPtr(destinationPath.UTF16String, sourcePath.UTF16String, NULL)) @throw [OFLinkItemFailedException exceptionWithSourceURL: source destinationURL: destination - errNo: retrieveError()]; + errNo: lastError()]; # endif objc_autoreleasePoolPop(pool); } #endif @@ -1407,11 +1407,11 @@ if (!createSymbolicLinkWFuncPtr(path.UTF16String, target.UTF16String, 0)) @throw [OFCreateSymbolicLinkFailedException exceptionWithURL: URL target: target - errNo: retrieveError()]; + errNo: lastError()]; # endif objc_autoreleasePoolPop(pool); } #endif @@ -1440,11 +1440,11 @@ [destination.fileSystemRepresentation cStringWithEncoding: encoding])) @throw [OFMoveItemFailedException exceptionWithSourceURL: source destinationURL: destination - errNo: retrieveError()]; + errNo: lastError()]; #else int status; # ifdef OF_WINDOWS if ([OFSystemInfo isWindowsNT]) Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -46,19 +46,19 @@ #import "OFURLHandler.h" #import "OFUTF8String.h" #import "OFUTF8String+Private.h" #import "OFXMLElement.h" +#import "OFGetItemAttributesFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFOpenItemFailedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" -#import "OFRetrieveItemAttributesFailedException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedProtocolException.h" #import "unicode.h" @@ -1002,11 +1002,11 @@ OFFile *file = nil; @try { fileSize = [[OFFileManager defaultManager] attributesOfItemAtPath: path].fileSize; - } @catch (OFRetrieveItemAttributesFailedException *e) { + } @catch (OFGetItemAttributesFailedException *e) { @throw [OFOpenItemFailedException exceptionWithPath: path mode: @"r" errNo: e.errNo]; } Index: src/ObjFW.h ================================================================== --- src/ObjFW.h +++ src/ObjFW.h @@ -176,10 +176,11 @@ #endif #import "OFEnumerationMutationException.h" #ifdef OF_HAVE_FILES # import "OFGetCurrentDirectoryFailedException.h" #endif +#import "OFGetItemAttributesFailedException.h" #import "OFGetOptionFailedException.h" #ifdef OF_WINDOWS # import "OFGetWindowsRegistryValueFailedException.h" #endif #import "OFHashAlreadyCalculatedException.h" @@ -218,11 +219,10 @@ #import "OFReadOrWriteFailedException.h" #import "OFRemoveItemFailedException.h" #ifdef OF_HAVE_SOCKETS # import "OFResolveHostFailedException.h" #endif -#import "OFRetrieveItemAttributesFailedException.h" #import "OFSeekFailedException.h" #import "OFSetItemAttributesFailedException.h" #import "OFSetOptionFailedException.h" #ifdef OF_WINDOWS # import "OFSetWindowsRegistryValueFailedException.h" Index: src/exceptions/Makefile ================================================================== --- src/exceptions/Makefile +++ src/exceptions/Makefile @@ -9,10 +9,11 @@ OFCopyItemFailedException.m \ OFCreateDirectoryFailedException.m \ OFCreateSymbolicLinkFailedException.m \ OFEnumerationMutationException.m \ OFException.m \ + OFGetItemAttributesFailedException.m \ OFGetOptionFailedException.m \ OFHashAlreadyCalculatedException.m \ OFHashNotCalculatedException.m \ OFInitializationFailedException.m \ OFInvalidArgumentException.m \ @@ -30,11 +31,10 @@ OFOutOfMemoryException.m \ OFOutOfRangeException.m \ OFReadFailedException.m \ OFReadOrWriteFailedException.m \ OFRemoveItemFailedException.m \ - OFRetrieveItemAttributesFailedException.m \ OFSeekFailedException.m \ OFSetItemAttributesFailedException.m \ OFSetOptionFailedException.m \ OFStillLockedException.m \ OFTruncatedDataException.m \ ADDED src/exceptions/OFGetItemAttributesFailedException.h Index: src/exceptions/OFGetItemAttributesFailedException.h ================================================================== --- src/exceptions/OFGetItemAttributesFailedException.h +++ src/exceptions/OFGetItemAttributesFailedException.h @@ -0,0 +1,71 @@ +/* + * 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 OFURL; + +/** + * @class OFGetItemAttributesFailedException \ + * OFGetItemAttributesFailedException.h \ + * ObjFW/OFGetItemAttributesFailedException.h + * + * @brief An exception indicating an item's attributes could not be retrieved. + */ +@interface OFGetItemAttributesFailedException: OFException +{ + OFURL *_URL; + int _errNo; + OF_RESERVE_IVARS(OFGetItemAttributesFailedException, 4) +} + +/** + * @brief The URL of the item whose attributes could not be retrieved. + */ +@property (readonly, nonatomic) OFURL *URL; + +/** + * @brief The errno of the error that occurred. + */ +@property (readonly, nonatomic) int errNo; + +/** + * @brief Creates a new, autoreleased retrieve item attributes failed exception. + * + * @param URL The URL of the item whose attributes could not be retrieved + * @param errNo The errno of the error that occurred + * @return A new, autoreleased retrieve item attributes failed exception + */ ++ (instancetype)exceptionWithURL: (OFURL *)URL errNo: (int)errNo; + ++ (instancetype)exception OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated retrieve item attributes failed + * exception. + * + * @param URL The URL of the item whose attributes could not be retrieved + * @param errNo The errno of the error that occurred + * @return An initialized retrieve item attributes failed exception + */ +- (instancetype)initWithURL: (OFURL *)URL + errNo: (int)errNo OF_DESIGNATED_INITIALIZER; + +- (instancetype)init OF_UNAVAILABLE; +@end + +OF_ASSUME_NONNULL_END ADDED src/exceptions/OFGetItemAttributesFailedException.m Index: src/exceptions/OFGetItemAttributesFailedException.m ================================================================== --- src/exceptions/OFGetItemAttributesFailedException.m +++ src/exceptions/OFGetItemAttributesFailedException.m @@ -0,0 +1,68 @@ +/* + * 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 "OFGetItemAttributesFailedException.h" +#import "OFString.h" +#import "OFURL.h" + +@implementation OFGetItemAttributesFailedException +@synthesize URL = _URL, errNo = _errNo; + ++ (instancetype)exception +{ + OF_UNRECOGNIZED_SELECTOR +} + ++ (instancetype)exceptionWithURL: (OFURL *)URL errNo: (int)errNo +{ + return [[[self alloc] initWithURL: URL errNo: errNo] autorelease]; +} + +- (instancetype)init +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)initWithURL: (OFURL *)URL errNo: (int)errNo +{ + self = [super init]; + + @try { + _URL = [URL copy]; + _errNo = errNo; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [_URL release]; + + [super dealloc]; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"Failed to get attributes for item %@: %@", + _URL, OFStrError(_errNo)]; +} +@end DELETED src/exceptions/OFRetrieveItemAttributesFailedException.h Index: src/exceptions/OFRetrieveItemAttributesFailedException.h ================================================================== --- src/exceptions/OFRetrieveItemAttributesFailedException.h +++ src/exceptions/OFRetrieveItemAttributesFailedException.h @@ -1,71 +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 OFURL; - -/** - * @class OFRetrieveItemAttributesFailedException \ - * OFRetrieveItemAttributesFailedException.h \ - * ObjFW/OFRetrieveItemAttributesFailedException.h - * - * @brief An exception indicating an item's attributes could not be retrieved. - */ -@interface OFRetrieveItemAttributesFailedException: OFException -{ - OFURL *_URL; - int _errNo; - OF_RESERVE_IVARS(OFRetrieveItemAttributesFailedException, 4) -} - -/** - * @brief The URL of the item whose attributes could not be retrieved. - */ -@property (readonly, nonatomic) OFURL *URL; - -/** - * @brief The errno of the error that occurred. - */ -@property (readonly, nonatomic) int errNo; - -/** - * @brief Creates a new, autoreleased retrieve item attributes failed exception. - * - * @param URL The URL of the item whose attributes could not be retrieved - * @param errNo The errno of the error that occurred - * @return A new, autoreleased retrieve item attributes failed exception - */ -+ (instancetype)exceptionWithURL: (OFURL *)URL errNo: (int)errNo; - -+ (instancetype)exception OF_UNAVAILABLE; - -/** - * @brief Initializes an already allocated retrieve item attributes failed - * exception. - * - * @param URL The URL of the item whose attributes could not be retrieved - * @param errNo The errno of the error that occurred - * @return An initialized retrieve item attributes failed exception - */ -- (instancetype)initWithURL: (OFURL *)URL - errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - -- (instancetype)init OF_UNAVAILABLE; -@end - -OF_ASSUME_NONNULL_END DELETED src/exceptions/OFRetrieveItemAttributesFailedException.m Index: src/exceptions/OFRetrieveItemAttributesFailedException.m ================================================================== --- src/exceptions/OFRetrieveItemAttributesFailedException.m +++ src/exceptions/OFRetrieveItemAttributesFailedException.m @@ -1,68 +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 "OFRetrieveItemAttributesFailedException.h" -#import "OFString.h" -#import "OFURL.h" - -@implementation OFRetrieveItemAttributesFailedException -@synthesize URL = _URL, errNo = _errNo; - -+ (instancetype)exception -{ - OF_UNRECOGNIZED_SELECTOR -} - -+ (instancetype)exceptionWithURL: (OFURL *)URL errNo: (int)errNo -{ - return [[[self alloc] initWithURL: URL errNo: errNo] autorelease]; -} - -- (instancetype)init -{ - OF_INVALID_INIT_METHOD -} - -- (instancetype)initWithURL: (OFURL *)URL errNo: (int)errNo -{ - self = [super init]; - - @try { - _URL = [URL copy]; - _errNo = errNo; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (void)dealloc -{ - [_URL release]; - - [super dealloc]; -} - -- (OFString *)description -{ - return [OFString stringWithFormat: - @"Failed to retrieve attributes for item %@: %@", - _URL, OFStrError(_errNo)]; -} -@end Index: utils/ofhttp/OFHTTP.m ================================================================== --- utils/ofhttp/OFHTTP.m +++ utils/ofhttp/OFHTTP.m @@ -39,19 +39,19 @@ #ifdef HAVE_TLS_SUPPORT # import "ObjFWTLS.h" #endif #import "OFConnectionFailedException.h" +#import "OFGetItemAttributesFailedException.h" #import "OFHTTPRequestFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFInvalidServerResponseException.h" #import "OFOpenItemFailedException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFResolveHostFailedException.h" -#import "OFRetrieveItemAttributesFailedException.h" #import "OFUnsupportedProtocolException.h" #import "OFWriteFailedException.h" #import "ProgressBar.h" @@ -353,11 +353,11 @@ contentLength = [OFString stringWithFormat: @"%ju", fileSize]; [_clientHeaders setObject: contentLength forKey: @"Content-Length"]; - } @catch (OFRetrieveItemAttributesFailedException *e) { + } @catch (OFGetItemAttributesFailedException *e) { } } if (contentLength == nil) [_clientHeaders setObject: @"chunked" @@ -1080,11 +1080,11 @@ _resumedFrom = (unsigned long long)size; range = [OFString stringWithFormat: @"bytes=%jd-", _resumedFrom]; [clientHeaders setObject: range forKey: @"Range"]; - } @catch (OFRetrieveItemAttributesFailedException *e) { + } @catch (OFGetItemAttributesFailedException *e) { } } if (!_quiet) { if (_useUnicode)