Index: src/OFFileManager.h ================================================================== --- src/OFFileManager.h +++ src/OFFileManager.h @@ -14,17 +14,14 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" -#import "OFDictionary.h" -#import "OFSeekableStream.h" +#import "OFURLHandler.h" OF_ASSUME_NONNULL_BEGIN -/*! @file */ - #if defined(OF_HAVE_CHMOD) && !defined(OF_AMIGAOS) # define OF_FILE_MANAGER_SUPPORTS_PERMISSIONS #endif #if defined(OF_HAVE_CHOWN) && !defined(OF_AMIGAOS) # define OF_FILE_MANAGER_SUPPORTS_OWNER @@ -38,194 +35,10 @@ @class OFArray OF_GENERIC(ObjectType); @class OFDate; @class OFURL; -/*! - * @brief A key for a file attribute in the file attributes dictionary. - * - * Possible keys for file URLs are: - * - * * @ref of_file_attribute_key_size - * * @ref of_file_attribute_key_type - * * @ref of_file_attribute_key_posix_permissions - * * @ref of_file_attribute_key_posix_uid - * * @ref of_file_attribute_key_posix_gid - * * @ref of_file_attribute_key_owner - * * @ref of_file_attribute_key_group - * * @ref of_file_attribute_key_last_access_date - * * @ref of_file_attribute_key_modification_date - * * @ref of_file_attribute_key_status_change_date - * * @ref of_file_attribute_key_symbolic_link_destination - * - * Other URL schemes might not have all keys and might have keys not listed. - */ -typedef OFConstantString *of_file_attribute_key_t; - -/*! - * @brief The type of a file. - * - * Possibles values for file URLs are: - * - * * @ref of_file_type_regular - * * @ref of_file_type_directory - * * @ref of_file_type_symbolic_link - * * @ref of_file_type_fifo - * * @ref of_file_type_character_special - * * @ref of_file_type_block_special - * * @ref of_file_type_socket - * - * Other URL schemes might not have all types and might have types not listed. - */ -typedef OFConstantString *of_file_type_t; - -/*! - * @brief A dictionary mapping keys of type @ref of_file_attribute_key_t - * to their attribute values. - */ -typedef OFDictionary OF_GENERIC(of_file_attribute_key_t, id) - *of_file_attributes_t; - -/*! - * @brief A mutable dictionary mapping keys of type - * @ref of_file_attribute_key_t to their attribute values. - */ -typedef OFMutableDictionary OF_GENERIC(of_file_attribute_key_t, id) - *of_mutable_file_attributes_t; - -#ifdef __cplusplus -extern "C" { -#endif -/*! - * @brief The size of the file as an @ref OFNumber. - * - * For convenience, a category on @ref OFDictionary is provided to access this - * via @ref OFDictionary#fileSize. - */ -extern const of_file_attribute_key_t of_file_attribute_key_size; - -/*! - * @brief The type of the file. - * - * The corresponding value is of type @ref of_file_type_t. - * - * For convenience, a category on @ref OFDictionary is provided to access this - * via @ref OFDictionary#fileType. - */ -extern const of_file_attribute_key_t of_file_attribute_key_type; - -/*! - * @brief The POSIX permissions of the file as an @ref OFNumber. - * - * For convenience, a category on @ref OFDictionary is provided to access this - * via @ref OFDictionary#filePOSIXPermissions. - */ -extern const of_file_attribute_key_t of_file_attribute_key_posix_permissions; - -/*! - * @brief The POSIX UID of the file as an @ref OFNumber. - * - * For convenience, a category on @ref OFDictionary is provided to access this - * via @ref OFDictionary#filePOSIXUID. - */ -extern const of_file_attribute_key_t of_file_attribute_key_posix_uid; - -/*! - * @brief The POSIX GID of the file as an @ref OFNumber. - * - * For convenience, a category on @ref OFDictionary is provided to access this - * via @ref OFDictionary#filePOSIXGID. - */ -extern const of_file_attribute_key_t of_file_attribute_key_posix_gid; - -/*! - * @brief The owner of the file as an @ref OFString. - * - * For convenience, a category on @ref OFDictionary is provided to access this - * via @ref OFDictionary#fileOwner. - */ -extern const of_file_attribute_key_t of_file_attribute_key_owner; - -/*! - * @brief The group of the file as an @ref OFString. - * - * For convenience, a category on @ref OFDictionary is provided to access this - * via @ref OFDictionary#fileGroup. - */ -extern const of_file_attribute_key_t of_file_attribute_key_group; - -/*! - * @brief The last access date of the file as an @ref OFDate. - * - * For convenience, a category on @ref OFDictionary is provided to access this - * via @ref OFDictionary#fileLastAccessDate. - */ -extern const of_file_attribute_key_t of_file_attribute_key_last_access_date; - -/*! - * @brief The last modification date of the file as an @ref OFDate. - * - * For convenience, a category on @ref OFDictionary is provided to access this - * via @ref OFDictionary#fileModificationDate. - */ -extern const of_file_attribute_key_t of_file_attribute_key_modification_date; - -/*! - * @brief The last status change date of the file as an @ref OFDate. - * - * For convenience, a category on @ref OFDictionary is provided to access this - * via @ref OFDictionary#fileStatusChangeDate. - */ -extern const of_file_attribute_key_t of_file_attribute_key_status_change_date; - -/*! - * @brief The destination of a symbolic link as an @ref OFString. - * - * For convenience, a category on @ref OFDictionary is provided to access this - * via @ref OFDictionary#fileSymbolicLinkDestination. - */ -extern const of_file_attribute_key_t - of_file_attribute_key_symbolic_link_destination; - -/*! - * @brief A regular file. - */ -extern const of_file_type_t of_file_type_regular; - -/*! - * @brief A directory. - */ -extern const of_file_type_t of_file_type_directory; - -/*! - * @brief A symbolic link. - */ -extern const of_file_type_t of_file_type_symbolic_link; - -/*! - * @brief A FIFO. - */ -extern const of_file_type_t of_file_type_fifo; - -/*! - * @brief A character special file. - */ -extern const of_file_type_t of_file_type_character_special; - -/*! - * @brief A block special file. - */ -extern const of_file_type_t of_file_type_block_special; - -/*! - * @brief A socket. - */ -extern const of_file_type_t of_file_type_socket; -#ifdef __cplusplus -} -#endif - /*! * @class OFFileManager OFFileManager.h ObjFW/OFFileManager.h * * @brief A class which provides management for files, e.g. reading contents of * directories, deleting files, renaming files, etc. @@ -535,86 +348,6 @@ */ - (void)createSymbolicLinkAtURL: (OFURL *)URL withDestinationPath: (OFString *)target; @end -@interface OFDictionary (FileAttributes) -/*! - * The @ref of_file_attribute_key_size key from the dictionary. - * - * Raises an @ref OFUndefinedKeyException if the key is missing. - */ -@property (readonly, nonatomic) uintmax_t fileSize; - -/*! - * The @ref of_file_attribute_key_type key from the dictionary. - * - * Raises an @ref OFUndefinedKeyException if the key is missing. - */ -@property (readonly, nonatomic) of_file_type_t fileType; - -/*! - * The @ref of_file_attribute_key_posix_permissions key from the dictionary. - * - * Raises an @ref OFUndefinedKeyException if the key is missing. - */ -@property (readonly, nonatomic) uint16_t filePOSIXPermissions; - -/*! - * The @ref of_file_attribute_key_posix_uid key from the dictionary. - * - * Raises an @ref OFUndefinedKeyException if the key is missing. - */ -@property (readonly, nonatomic) uint32_t filePOSIXUID; - -/*! - * The @ref of_file_attribute_key_posix_gid key from the dictionary. - * - * Raises an @ref OFUndefinedKeyException if the key is missing. - */ -@property (readonly, nonatomic) uint32_t filePOSIXGID; - -/*! - * The @ref of_file_attribute_key_owner key from the dictionary. - * - * Raises an @ref OFUndefinedKeyException if the key is missing. - */ -@property (readonly, nonatomic) OFString *fileOwner; - -/*! - * The @ref of_file_attribute_key_group key from the dictionary. - * - * Raises an @ref OFUndefinedKeyException if the key is missing. - */ -@property (readonly, nonatomic) OFString *fileGroup; - -/*! - * The @ref of_file_attribute_key_last_access_date key from the dictionary. - * - * Raises an @ref OFUndefinedKeyException if the key is missing. - */ -@property (readonly, nonatomic) OFDate *fileLastAccessDate; - -/*! - * The @ref of_file_attribute_key_modification_date key from the dictionary. - * - * Raises an @ref OFUndefinedKeyException if the key is missing. - */ -@property (readonly, nonatomic) OFDate *fileModificationDate; - -/*! - * The @ref of_file_attribute_key_status_change_date key from the dictionary. - * - * Raises an @ref OFUndefinedKeyException if the key is missing. - */ -@property (readonly, nonatomic) OFDate *fileStatusChangeDate; - -/*! - * The @ref of_file_attribute_key_symbolic_link_destination key from the - * dictionary. - * - * Raises an @ref OFUndefinedKeyException if the key is missing. - */ -@property (readonly, nonatomic) OFString *fileSymbolicLinkDestination; -@end - OF_ASSUME_NONNULL_END Index: src/OFFileManager.m ================================================================== --- src/OFFileManager.m +++ src/OFFileManager.m @@ -47,11 +47,10 @@ #import "OFMoveItemFailedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFRemoveItemFailedException.h" #import "OFRetrieveItemAttributesFailedException.h" -#import "OFUndefinedKeyException.h" #import "OFUnsupportedProtocolException.h" #ifdef OF_WINDOWS # include # include @@ -78,42 +77,10 @@ static struct DOSIFace *IDOS = NULL; #endif static OFFileManager *defaultManager; -const of_file_attribute_key_t of_file_attribute_key_size = - @"of_file_attribute_key_size"; -const of_file_attribute_key_t of_file_attribute_key_type = - @"of_file_attribute_key_type"; -const of_file_attribute_key_t of_file_attribute_key_posix_permissions = - @"of_file_attribute_key_posix_permissions"; -const of_file_attribute_key_t of_file_attribute_key_posix_uid = - @"of_file_attribute_key_posix_uid"; -const of_file_attribute_key_t of_file_attribute_key_posix_gid = - @"of_file_attribute_key_posix_gid"; -const of_file_attribute_key_t of_file_attribute_key_owner = - @"of_file_attribute_key_owner"; -const of_file_attribute_key_t of_file_attribute_key_group = - @"of_file_attribute_key_group"; -const of_file_attribute_key_t of_file_attribute_key_last_access_date = - @"of_file_attribute_key_last_access_date"; -const of_file_attribute_key_t of_file_attribute_key_modification_date = - @"of_file_attribute_key_modification_date"; -const of_file_attribute_key_t of_file_attribute_key_status_change_date = - @"of_file_attribute_key_status_change_date"; -const of_file_attribute_key_t of_file_attribute_key_symbolic_link_destination = - @"of_file_attribute_key_symbolic_link_destination"; - -const of_file_type_t of_file_type_regular = @"of_file_type_regular"; -const of_file_type_t of_file_type_directory = @"of_file_type_directory"; -const of_file_type_t of_file_type_symbolic_link = @"of_file_type_symbolic_link"; -const of_file_type_t of_file_type_fifo = @"of_file_type_fifo"; -const of_file_type_t of_file_type_character_special = - @"of_file_type_character_special"; -const of_file_type_t of_file_type_block_special = @"of_file_type_block_special"; -const of_file_type_t of_file_type_socket = @"of_file_type_socket"; - #ifdef OF_AMIGAOS static bool dirChanged = false; static BPTR originalDirLock = 0; OF_DESTRUCTOR() @@ -129,23 +96,10 @@ CloseLibrary(DOSBase); # endif } #endif -static id -attributeForKeyOrException(of_file_attributes_t attributes, - of_file_attribute_key_t key) -{ - id object = [attributes objectForKey: key]; - - if (object == nil) - @throw [OFUndefinedKeyException exceptionWithObject: attributes - key: key]; - - return object; -} - @implementation OFFileManager + (void)initialize { if (self != [OFFileManager class]) return; @@ -836,75 +790,10 @@ withDestinationPath: target]; objc_autoreleasePoolPop(pool); } #endif -@end - -@implementation OFDictionary (FileAttributes) -- (uintmax_t)fileSize -{ - return [attributeForKeyOrException(self, of_file_attribute_key_size) - uIntMaxValue]; -} - -- (of_file_type_t)fileType -{ - return attributeForKeyOrException(self, of_file_attribute_key_type); -} - -- (uint16_t)filePOSIXPermissions -{ - return [attributeForKeyOrException(self, - of_file_attribute_key_posix_permissions) uInt16Value]; -} - -- (uint32_t)filePOSIXUID -{ - return [attributeForKeyOrException(self, - of_file_attribute_key_posix_uid) uInt32Value]; -} - -- (uint32_t)filePOSIXGID -{ - return [attributeForKeyOrException(self, - of_file_attribute_key_posix_gid) uInt32Value]; -} - -- (OFString *)fileOwner -{ - return attributeForKeyOrException(self, of_file_attribute_key_owner); -} - -- (OFString *)fileGroup -{ - return attributeForKeyOrException(self, of_file_attribute_key_group); -} - -- (OFDate *)fileLastAccessDate -{ - return attributeForKeyOrException(self, - of_file_attribute_key_last_access_date); -} - -- (OFDate *)fileModificationDate -{ - return attributeForKeyOrException(self, - of_file_attribute_key_modification_date); -} - -- (OFDate *)fileStatusChangeDate -{ - return attributeForKeyOrException(self, - of_file_attribute_key_status_change_date); -} - -- (OFString *)fileSymbolicLinkDestination -{ - return attributeForKeyOrException(self, - of_file_attribute_key_symbolic_link_destination); -} @end @implementation OFFileManager_default - (instancetype)autorelease { Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -35,15 +35,16 @@ #import "OFString_UTF8+Private.h" #import "OFArray.h" #import "OFCharacterSet.h" #import "OFData.h" #import "OFDictionary.h" -#import "OFLocale.h" #ifdef OF_HAVE_FILES # import "OFFile.h" # import "OFFileManager.h" #endif +#import "OFLocale.h" +#import "OFStream.h" #import "OFURL.h" #import "OFURLHandler.h" #import "OFXMLElement.h" #import "OFInitializationFailedException.h" Index: src/OFURLHandler.h ================================================================== --- src/OFURLHandler.h +++ src/OFURLHandler.h @@ -14,17 +14,206 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" -#import "OFFileManager.h" +#import "OFDictionary.h" +#import "OFString.h" OF_ASSUME_NONNULL_BEGIN -@class OFString; +/*! @file */ + +@class OFArray OF_GENERIC(ObjectType); +@class OFDate; +@class OFStream; @class OFURL; +/*! + * @brief A key for a file attribute in the file attributes dictionary. + * + * Possible keys for file URLs are: + * + * * @ref of_file_attribute_key_size + * * @ref of_file_attribute_key_type + * * @ref of_file_attribute_key_posix_permissions + * * @ref of_file_attribute_key_posix_uid + * * @ref of_file_attribute_key_posix_gid + * * @ref of_file_attribute_key_owner + * * @ref of_file_attribute_key_group + * * @ref of_file_attribute_key_last_access_date + * * @ref of_file_attribute_key_modification_date + * * @ref of_file_attribute_key_status_change_date + * * @ref of_file_attribute_key_symbolic_link_destination + * + * Other URL schemes might not have all keys and might have keys not listed. + */ +typedef OFConstantString *of_file_attribute_key_t; + +/*! + * @brief The type of a file. + * + * Possibles values for file URLs are: + * + * * @ref of_file_type_regular + * * @ref of_file_type_directory + * * @ref of_file_type_symbolic_link + * * @ref of_file_type_fifo + * * @ref of_file_type_character_special + * * @ref of_file_type_block_special + * * @ref of_file_type_socket + * + * Other URL schemes might not have all types and might have types not listed. + */ +typedef OFConstantString *of_file_type_t; + +/*! + * @brief A dictionary mapping keys of type @ref of_file_attribute_key_t + * to their attribute values. + */ +typedef OFDictionary OF_GENERIC(of_file_attribute_key_t, id) + *of_file_attributes_t; + +/*! + * @brief A mutable dictionary mapping keys of type + * @ref of_file_attribute_key_t to their attribute values. + */ +typedef OFMutableDictionary OF_GENERIC(of_file_attribute_key_t, id) + *of_mutable_file_attributes_t; + +#ifdef __cplusplus +extern "C" { +#endif +/*! + * @brief The size of the file as an @ref OFNumber. + * + * For convenience, a category on @ref OFDictionary is provided to access this + * via @ref OFDictionary#fileSize. + */ +extern const of_file_attribute_key_t of_file_attribute_key_size; + +/*! + * @brief The type of the file. + * + * The corresponding value is of type @ref of_file_type_t. + * + * For convenience, a category on @ref OFDictionary is provided to access this + * via @ref OFDictionary#fileType. + */ +extern const of_file_attribute_key_t of_file_attribute_key_type; + +/*! + * @brief The POSIX permissions of the file as an @ref OFNumber. + * + * For convenience, a category on @ref OFDictionary is provided to access this + * via @ref OFDictionary#filePOSIXPermissions. + */ +extern const of_file_attribute_key_t of_file_attribute_key_posix_permissions; + +/*! + * @brief The POSIX UID of the file as an @ref OFNumber. + * + * For convenience, a category on @ref OFDictionary is provided to access this + * via @ref OFDictionary#filePOSIXUID. + */ +extern const of_file_attribute_key_t of_file_attribute_key_posix_uid; + +/*! + * @brief The POSIX GID of the file as an @ref OFNumber. + * + * For convenience, a category on @ref OFDictionary is provided to access this + * via @ref OFDictionary#filePOSIXGID. + */ +extern const of_file_attribute_key_t of_file_attribute_key_posix_gid; + +/*! + * @brief The owner of the file as an @ref OFString. + * + * For convenience, a category on @ref OFDictionary is provided to access this + * via @ref OFDictionary#fileOwner. + */ +extern const of_file_attribute_key_t of_file_attribute_key_owner; + +/*! + * @brief The group of the file as an @ref OFString. + * + * For convenience, a category on @ref OFDictionary is provided to access this + * via @ref OFDictionary#fileGroup. + */ +extern const of_file_attribute_key_t of_file_attribute_key_group; + +/*! + * @brief The last access date of the file as an @ref OFDate. + * + * For convenience, a category on @ref OFDictionary is provided to access this + * via @ref OFDictionary#fileLastAccessDate. + */ +extern const of_file_attribute_key_t of_file_attribute_key_last_access_date; + +/*! + * @brief The last modification date of the file as an @ref OFDate. + * + * For convenience, a category on @ref OFDictionary is provided to access this + * via @ref OFDictionary#fileModificationDate. + */ +extern const of_file_attribute_key_t of_file_attribute_key_modification_date; + +/*! + * @brief The last status change date of the file as an @ref OFDate. + * + * For convenience, a category on @ref OFDictionary is provided to access this + * via @ref OFDictionary#fileStatusChangeDate. + */ +extern const of_file_attribute_key_t of_file_attribute_key_status_change_date; + +/*! + * @brief The destination of a symbolic link as an @ref OFString. + * + * For convenience, a category on @ref OFDictionary is provided to access this + * via @ref OFDictionary#fileSymbolicLinkDestination. + */ +extern const of_file_attribute_key_t + of_file_attribute_key_symbolic_link_destination; + +/*! + * @brief A regular file. + */ +extern const of_file_type_t of_file_type_regular; + +/*! + * @brief A directory. + */ +extern const of_file_type_t of_file_type_directory; + +/*! + * @brief A symbolic link. + */ +extern const of_file_type_t of_file_type_symbolic_link; + +/*! + * @brief A FIFO. + */ +extern const of_file_type_t of_file_type_fifo; + +/*! + * @brief A character special file. + */ +extern const of_file_type_t of_file_type_character_special; + +/*! + * @brief A block special file. + */ +extern const of_file_type_t of_file_type_block_special; + +/*! + * @brief A socket. + */ +extern const of_file_type_t of_file_type_socket; +#ifdef __cplusplus +} +#endif + /*! * @class OFURLHandler OFURLHandler.h ObjFW/OFURLHandler.h * * @brief A handler for a URL scheme. */ @@ -223,7 +412,87 @@ * reported via exceptions and not by returning false! */ - (bool)moveItemAtURL: (OFURL *)source toURL: (OFURL *)destination; @end + +@interface OFDictionary (FileAttributes) +/*! + * The @ref of_file_attribute_key_size key from the dictionary. + * + * Raises an @ref OFUndefinedKeyException if the key is missing. + */ +@property (readonly, nonatomic) uintmax_t fileSize; + +/*! + * The @ref of_file_attribute_key_type key from the dictionary. + * + * Raises an @ref OFUndefinedKeyException if the key is missing. + */ +@property (readonly, nonatomic) of_file_type_t fileType; + +/*! + * The @ref of_file_attribute_key_posix_permissions key from the dictionary. + * + * Raises an @ref OFUndefinedKeyException if the key is missing. + */ +@property (readonly, nonatomic) uint16_t filePOSIXPermissions; + +/*! + * The @ref of_file_attribute_key_posix_uid key from the dictionary. + * + * Raises an @ref OFUndefinedKeyException if the key is missing. + */ +@property (readonly, nonatomic) uint32_t filePOSIXUID; + +/*! + * The @ref of_file_attribute_key_posix_gid key from the dictionary. + * + * Raises an @ref OFUndefinedKeyException if the key is missing. + */ +@property (readonly, nonatomic) uint32_t filePOSIXGID; + +/*! + * The @ref of_file_attribute_key_owner key from the dictionary. + * + * Raises an @ref OFUndefinedKeyException if the key is missing. + */ +@property (readonly, nonatomic) OFString *fileOwner; + +/*! + * The @ref of_file_attribute_key_group key from the dictionary. + * + * Raises an @ref OFUndefinedKeyException if the key is missing. + */ +@property (readonly, nonatomic) OFString *fileGroup; + +/*! + * The @ref of_file_attribute_key_last_access_date key from the dictionary. + * + * Raises an @ref OFUndefinedKeyException if the key is missing. + */ +@property (readonly, nonatomic) OFDate *fileLastAccessDate; + +/*! + * The @ref of_file_attribute_key_modification_date key from the dictionary. + * + * Raises an @ref OFUndefinedKeyException if the key is missing. + */ +@property (readonly, nonatomic) OFDate *fileModificationDate; + +/*! + * The @ref of_file_attribute_key_status_change_date key from the dictionary. + * + * Raises an @ref OFUndefinedKeyException if the key is missing. + */ +@property (readonly, nonatomic) OFDate *fileStatusChangeDate; + +/*! + * The @ref of_file_attribute_key_symbolic_link_destination key from the + * dictionary. + * + * Raises an @ref OFUndefinedKeyException if the key is missing. + */ +@property (readonly, nonatomic) OFString *fileSymbolicLinkDestination; +@end OF_ASSUME_NONNULL_END Index: src/OFURLHandler.m ================================================================== --- src/OFURLHandler.m +++ src/OFURLHandler.m @@ -16,10 +16,11 @@ */ #include "config.h" #import "OFURLHandler.h" +#import "OFNumber.h" #import "OFURL.h" #ifdef OF_HAVE_THREADS # import "OFMutex.h" #endif @@ -29,14 +30,61 @@ #endif #if defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_THREADS) # import "OFURLHandler_HTTP.h" #endif +#import "OFUndefinedKeyException.h" + +const of_file_attribute_key_t of_file_attribute_key_size = + @"of_file_attribute_key_size"; +const of_file_attribute_key_t of_file_attribute_key_type = + @"of_file_attribute_key_type"; +const of_file_attribute_key_t of_file_attribute_key_posix_permissions = + @"of_file_attribute_key_posix_permissions"; +const of_file_attribute_key_t of_file_attribute_key_posix_uid = + @"of_file_attribute_key_posix_uid"; +const of_file_attribute_key_t of_file_attribute_key_posix_gid = + @"of_file_attribute_key_posix_gid"; +const of_file_attribute_key_t of_file_attribute_key_owner = + @"of_file_attribute_key_owner"; +const of_file_attribute_key_t of_file_attribute_key_group = + @"of_file_attribute_key_group"; +const of_file_attribute_key_t of_file_attribute_key_last_access_date = + @"of_file_attribute_key_last_access_date"; +const of_file_attribute_key_t of_file_attribute_key_modification_date = + @"of_file_attribute_key_modification_date"; +const of_file_attribute_key_t of_file_attribute_key_status_change_date = + @"of_file_attribute_key_status_change_date"; +const of_file_attribute_key_t of_file_attribute_key_symbolic_link_destination = + @"of_file_attribute_key_symbolic_link_destination"; + +const of_file_type_t of_file_type_regular = @"of_file_type_regular"; +const of_file_type_t of_file_type_directory = @"of_file_type_directory"; +const of_file_type_t of_file_type_symbolic_link = @"of_file_type_symbolic_link"; +const of_file_type_t of_file_type_fifo = @"of_file_type_fifo"; +const of_file_type_t of_file_type_character_special = + @"of_file_type_character_special"; +const of_file_type_t of_file_type_block_special = @"of_file_type_block_special"; +const of_file_type_t of_file_type_socket = @"of_file_type_socket"; + static OFMutableDictionary OF_GENERIC(OFString *, OFURLHandler *) *handlers; #ifdef OF_HAVE_THREADS static OFMutex *mutex; #endif + +static id +attributeForKeyOrException(of_file_attributes_t attributes, + of_file_attribute_key_t key) +{ + id object = [attributes objectForKey: key]; + + if (object == nil) + @throw [OFUndefinedKeyException exceptionWithObject: attributes + key: key]; + + return object; +} @implementation OFURLHandler @synthesize scheme = _scheme; + (void)initialize @@ -193,5 +241,70 @@ toURL: (OFURL *)destination { return false; } @end + +@implementation OFDictionary (FileAttributes) +- (uintmax_t)fileSize +{ + return [attributeForKeyOrException(self, of_file_attribute_key_size) + uIntMaxValue]; +} + +- (of_file_type_t)fileType +{ + return attributeForKeyOrException(self, of_file_attribute_key_type); +} + +- (uint16_t)filePOSIXPermissions +{ + return [attributeForKeyOrException(self, + of_file_attribute_key_posix_permissions) uInt16Value]; +} + +- (uint32_t)filePOSIXUID +{ + return [attributeForKeyOrException(self, + of_file_attribute_key_posix_uid) uInt32Value]; +} + +- (uint32_t)filePOSIXGID +{ + return [attributeForKeyOrException(self, + of_file_attribute_key_posix_gid) uInt32Value]; +} + +- (OFString *)fileOwner +{ + return attributeForKeyOrException(self, of_file_attribute_key_owner); +} + +- (OFString *)fileGroup +{ + return attributeForKeyOrException(self, of_file_attribute_key_group); +} + +- (OFDate *)fileLastAccessDate +{ + return attributeForKeyOrException(self, + of_file_attribute_key_last_access_date); +} + +- (OFDate *)fileModificationDate +{ + return attributeForKeyOrException(self, + of_file_attribute_key_modification_date); +} + +- (OFDate *)fileStatusChangeDate +{ + return attributeForKeyOrException(self, + of_file_attribute_key_status_change_date); +} + +- (OFString *)fileSymbolicLinkDestination +{ + return attributeForKeyOrException(self, + of_file_attribute_key_symbolic_link_destination); +} +@end Index: src/exceptions/OFSetItemAttributesFailedException.h ================================================================== --- src/exceptions/OFSetItemAttributesFailedException.h +++ src/exceptions/OFSetItemAttributesFailedException.h @@ -14,11 +14,11 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFException.h" -#import "OFFileManager.h" +#import "OFURLHandler.h" OF_ASSUME_NONNULL_BEGIN @class OFURL;