Index: ObjFW.xcodeproj/project.pbxproj ================================================================== --- ObjFW.xcodeproj/project.pbxproj +++ ObjFW.xcodeproj/project.pbxproj @@ -318,10 +318,12 @@ 4B6C8ADC17BD5C2E00B194F2 /* OFThread+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B6C8AD517BD5C2E00B194F2 /* OFThread+Private.h */; }; 4B6C8ADD17BD5C2E00B194F2 /* OFTimer+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B6C8AD617BD5C2E00B194F2 /* OFTimer+Private.h */; }; 4B6C8ADE17BD5C2E00B194F2 /* OFZIPArchiveEntry+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B6C8AD717BD5C2E00B194F2 /* OFZIPArchiveEntry+Private.h */; }; 4B7161AD17A6FC7600B74970 /* OFHTTPResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B7161AB17A6FC7600B74970 /* OFHTTPResponse.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B7161AE17A6FC7600B74970 /* OFHTTPResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B7161AC17A6FC7600B74970 /* OFHTTPResponse.m */; }; + 4B72F7DE1AD9311B00CE253C /* OFStatItemFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B72F7DC1AD9311B00CE253C /* OFStatItemFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4B72F7DF1AD9311B00CE253C /* OFStatItemFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B72F7DD1AD9311B00CE253C /* OFStatItemFailedException.m */; }; 4B745BA5168B25E600A6C20E /* OFSystemInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B745BA3168B25E600A6C20E /* OFSystemInfo.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B745BA6168B25E600A6C20E /* OFSystemInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B745BA4168B25E600A6C20E /* OFSystemInfo.m */; }; 4B7769ED1895C07D00D12284 /* resolver.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B7769EB1895C07D00D12284 /* resolver.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B7769EE1895C07D00D12284 /* resolver.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B7769EC1895C07D00D12284 /* resolver.m */; }; 4B7769F11895ED0C00D12284 /* OFUDPSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B7769EF1895ED0C00D12284 /* OFUDPSocket.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -808,10 +810,12 @@ 4B6EF6811235358D0076B512 /* TestsAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TestsAppDelegate.m; path = tests/TestsAppDelegate.m; sourceTree = SOURCE_ROOT; }; 4B6EF684123535B60076B512 /* TestPlugin.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TestPlugin.m; path = tests/plugin/TestPlugin.m; sourceTree = SOURCE_ROOT; }; 4B6EF685123535C80076B512 /* test.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = test.m; path = tests/objc_sync/test.m; sourceTree = SOURCE_ROOT; }; 4B7161AB17A6FC7600B74970 /* OFHTTPResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFHTTPResponse.h; path = src/OFHTTPResponse.h; sourceTree = ""; }; 4B7161AC17A6FC7600B74970 /* OFHTTPResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFHTTPResponse.m; path = src/OFHTTPResponse.m; sourceTree = ""; }; + 4B72F7DC1AD9311B00CE253C /* OFStatItemFailedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFStatItemFailedException.h; path = src/exceptions/OFStatItemFailedException.h; sourceTree = ""; }; + 4B72F7DD1AD9311B00CE253C /* OFStatItemFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFStatItemFailedException.m; path = src/exceptions/OFStatItemFailedException.m; sourceTree = ""; }; 4B745BA3168B25E600A6C20E /* OFSystemInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFSystemInfo.h; path = src/OFSystemInfo.h; sourceTree = ""; }; 4B745BA4168B25E600A6C20E /* OFSystemInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFSystemInfo.m; path = src/OFSystemInfo.m; sourceTree = ""; }; 4B7769EB1895C07D00D12284 /* resolver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = resolver.h; path = src/resolver.h; sourceTree = ""; }; 4B7769EC1895C07D00D12284 /* resolver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = resolver.m; path = src/resolver.m; sourceTree = ""; }; 4B7769EF1895ED0C00D12284 /* OFUDPSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFUDPSocket.h; path = src/OFUDPSocket.h; sourceTree = ""; }; @@ -1107,10 +1111,12 @@ 4BFF3711177E17C100192782 /* OFRemoveItemFailedException.m */, 4B29BC39133AC4E80004B236 /* OFSeekFailedException.h */, 4B29BC3A133AC4E80004B236 /* OFSeekFailedException.m */, 4B90B78B133AD46700BD33CB /* OFSetOptionFailedException.h */, 4B90B78C133AD46700BD33CB /* OFSetOptionFailedException.m */, + 4B72F7DC1AD9311B00CE253C /* OFStatItemFailedException.h */, + 4B72F7DD1AD9311B00CE253C /* OFStatItemFailedException.m */, 4B6743ED163C384A00EB1E59 /* OFStillLockedException.h */, 4B6743EE163C384A00EB1E59 /* OFStillLockedException.m */, 4B55A0F9133ABEA900B58A93 /* OFThreadJoinFailedException.h */, 4B55A0FA133ABEA900B58A93 /* OFThreadJoinFailedException.m */, 4B55A0FB133ABEA900B58A93 /* OFThreadStartFailedException.h */, @@ -1747,10 +1753,11 @@ 4B55A112133AC24600B58A93 /* OFReadFailedException.h in Headers */, 4B55A114133AC24600B58A93 /* OFReadOrWriteFailedException.h in Headers */, 4BFF3714177E17C100192782 /* OFRemoveItemFailedException.h in Headers */, 4B29BC41133AC4E80004B236 /* OFSeekFailedException.h in Headers */, 4B90B791133AD46700BD33CB /* OFSetOptionFailedException.h in Headers */, + 4B72F7DE1AD9311B00CE253C /* OFStatItemFailedException.h in Headers */, 4B6743F3163C384A00EB1E59 /* OFStillLockedException.h in Headers */, 4B17FFA9133A34E7003E6DCD /* OFTruncatedDataException.h in Headers */, 4B55A0FF133ABEA900B58A93 /* OFThreadJoinFailedException.h in Headers */, 4B55A101133ABEA900B58A93 /* OFThreadStartFailedException.h in Headers */, 4B55A103133ABEA900B58A93 /* OFThreadStillRunningException.h in Headers */, @@ -2126,10 +2133,11 @@ 4B55A113133AC24600B58A93 /* OFReadFailedException.m in Sources */, 4B55A115133AC24600B58A93 /* OFReadOrWriteFailedException.m in Sources */, 4BFF3715177E17C100192782 /* OFRemoveItemFailedException.m in Sources */, 4B29BC42133AC4E80004B236 /* OFSeekFailedException.m in Sources */, 4B90B792133AD46700BD33CB /* OFSetOptionFailedException.m in Sources */, + 4B72F7DF1AD9311B00CE253C /* OFStatItemFailedException.m in Sources */, 4B6743F4163C384A00EB1E59 /* OFStillLockedException.m in Sources */, 4B55A100133ABEA900B58A93 /* OFThreadJoinFailedException.m in Sources */, 4B55A102133ABEA900B58A93 /* OFThreadStartFailedException.m in Sources */, 4B55A104133ABEA900B58A93 /* OFThreadStillRunningException.m in Sources */, 4B17FFAA133A34E7003E6DCD /* OFTruncatedDataException.m in Sources */, Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -80,10 +80,11 @@ #import "OFOpenItemFailedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFRemoveItemFailedException.h" +#import "OFStatItemFailedException.h" #import "OFSeekFailedException.h" #import "OFUnlockFailedException.h" #import "OFWriteFailedException.h" #ifdef _WIN32 @@ -521,12 +522,11 @@ if (path == nil) @throw [OFInvalidArgumentException exception]; if (of_stat(path, &s) != 0) - /* FIXME: Maybe use another exception? */ - @throw [OFOpenItemFailedException exceptionWithPath: path + @throw [OFStatItemFailedException exceptionWithPath: path errNo: errno]; return s.st_size; } @@ -536,12 +536,11 @@ if (path == nil) @throw [OFInvalidArgumentException exception]; if (of_stat(path, &s) != 0) - /* FIXME: Maybe use another exception? */ - @throw [OFOpenItemFailedException exceptionWithPath: path + @throw [OFStatItemFailedException exceptionWithPath: path errNo: errno]; /* FIXME: We could be more precise on some OSes */ return [OFDate dateWithTimeIntervalSince1970: s.st_atime]; } @@ -552,12 +551,11 @@ if (path == nil) @throw [OFInvalidArgumentException exception]; if (of_stat(path, &s) != 0) - /* FIXME: Maybe use another exception? */ - @throw [OFOpenItemFailedException exceptionWithPath: path + @throw [OFStatItemFailedException exceptionWithPath: path errNo: errno]; /* FIXME: We could be more precise on some OSes */ return [OFDate dateWithTimeIntervalSince1970: s.st_mtime]; } @@ -568,12 +566,11 @@ if (path == nil) @throw [OFInvalidArgumentException exception]; if (of_stat(path, &s) != 0) - /* FIXME: Maybe use another exception? */ - @throw [OFOpenItemFailedException exceptionWithPath: path + @throw [OFStatItemFailedException exceptionWithPath: path errNo: errno]; /* FIXME: We could be more precise on some OSes */ return [OFDate dateWithTimeIntervalSince1970: s.st_ctime]; } @@ -986,12 +983,11 @@ encoding = [OFSystemInfo native8BitEncoding]; length = readlink([path cStringWithEncoding: encoding], destination, PATH_MAX); if (length < 0) - /* FIXME: Maybe use another exception? */ - @throw [OFOpenItemFailedException exceptionWithPath: path + @throw [OFStatItemFailedException exceptionWithPath: path errNo: errno]; return [OFString stringWithCString: destination encoding: encoding length: length]; Index: src/exceptions/Makefile ================================================================== --- src/exceptions/Makefile +++ src/exceptions/Makefile @@ -32,10 +32,11 @@ OFReadFailedException.m \ OFReadOrWriteFailedException.m \ OFRemoveItemFailedException.m \ OFSeekFailedException.m \ OFSetOptionFailedException.m \ + OFStatItemFailedException.m \ OFStillLockedException.m \ OFTruncatedDataException.m \ OFUnboundNamespaceException.m \ OFUnboundPrefixException.m \ OFUnknownXMLEntityException.m \ ADDED src/exceptions/OFStatItemFailedException.h Index: src/exceptions/OFStatItemFailedException.h ================================================================== --- src/exceptions/OFStatItemFailedException.h +++ src/exceptions/OFStatItemFailedException.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 + * 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" + +/*! + * @class OFStatItemFailedException \ + * OFStatItemFailedException.h ObjFW/OFStatItemFailedException.h + * + * @brief An exception indicating an item's status could not be retrieved. + */ +@interface OFStatItemFailedException: OFException +{ + OFString *_path; + int _errNo; +} + +#ifdef OF_HAVE_PROPERTIES +@property (readonly, copy) OFString *path; +@property (readonly) int errNo; +#endif + +/*! + * @brief Creates a new, autoreleased stat item failed exception. + * + * @param path A string with the path of the item whose status could not be + * retrieved + * @return A new, autoreleased stat item failed exception + */ ++ (instancetype)exceptionWithPath: (OFString*)path; + +/*! + * @brief Creates a new, autoreleased stat item failed exception. + * + * @param path A string with the path of the item whose status could not be + * retrieved + * @param errNo The errno of the error + * @return A new, autoreleased stat item failed exception + */ ++ (instancetype)exceptionWithPath: (OFString*)path + errNo: (int)errNo; + +/*! + * @brief Initializes an already allocated stat item failed exception. + * + * @param path A string with the path of the item whose status could not be + * retrieved + * @return An initialized stat item failed exception + */ +- initWithPath: (OFString*)path; + +/*! + * @brief Initializes an already allocated stat item failed exception. + * + * @param path A string with the path of the item whose status could not be + * retrieved + * @param errNo The errno of the error + * @return An initialized stat item failed exception + */ +- initWithPath: (OFString*)path + errNo: (int)errNo; + +/*! + * @brief Returns a string with the path of the item whose status could not be + * retrieved. + * + * @return A string with the path of the item whose status could not be + * retrieved + */ +- (OFString*)path; + +/*! + * @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/OFStatItemFailedException.m Index: src/exceptions/OFStatItemFailedException.m ================================================================== --- src/exceptions/OFStatItemFailedException.m +++ src/exceptions/OFStatItemFailedException.m @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 + * 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 "OFStatItemFailedException.h" +#import "OFString.h" + +@implementation OFStatItemFailedException ++ (instancetype)exceptionWithPath: (OFString*)path +{ + return [[[self alloc] initWithPath: path] autorelease]; +} + ++ (instancetype)exceptionWithPath: (OFString*)path + errNo: (int)errNo +{ + return [[[self alloc] initWithPath: path + errNo: errNo] autorelease]; +} + +- init +{ + OF_INVALID_INIT_METHOD +} + +- initWithPath: (OFString*)path +{ + self = [super init]; + + @try { + _path = [path copy]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- initWithPath: (OFString*)path + errNo: (int)errNo +{ + self = [super init]; + + @try { + _path = [path copy]; + _errNo = errNo; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [_path release]; + + [super dealloc]; +} + +- (OFString*)description +{ + if (_errNo != 0) + return [OFString stringWithFormat: + @"Failed to stat item %@: %@", _path, of_strerror(_errNo)]; + else + return [OFString stringWithFormat: + @"Failed to stat item %@!", _path]; +} + +- (OFString*)path +{ + OF_GETTER(_path, true) +} + +- (int)errNo +{ + return _errNo; +} +@end