@@ -89,12 +89,11 @@ UnLock(CurrentDir(originalDirLock)); } #endif static id -attributeForKeyOrException(of_file_attributes_t attributes, - of_file_attribute_key_t key) +attributeForKeyOrException(OFFileAttributes attributes, OFFileAttributeKey key) { id object = [attributes objectForKey: key]; if (object == nil) @throw [OFUndefinedKeyException exceptionWithObject: attributes @@ -197,11 +196,11 @@ objc_autoreleasePoolPop(pool); return [ret autorelease]; } #endif -- (of_file_attributes_t)attributesOfItemAtURL: (OFURL *)URL +- (OFFileAttributes)attributesOfItemAtURL: (OFURL *)URL { OFURLHandler *URLHandler; if (URL == nil) @throw [OFInvalidArgumentException exception]; @@ -211,14 +210,14 @@ return [URLHandler attributesOfItemAtURL: URL]; } #ifdef OF_HAVE_FILES -- (of_file_attributes_t)attributesOfItemAtPath: (OFString *)path +- (OFFileAttributes)attributesOfItemAtPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); - of_file_attributes_t ret; + OFFileAttributes ret; ret = [self attributesOfItemAtURL: [OFURL fileURLWithPath: path]]; [ret retain]; @@ -226,34 +225,30 @@ return [ret autorelease]; } #endif -- (void)setAttributes: (of_file_attributes_t)attributes - ofItemAtURL: (OFURL *)URL +- (void)setAttributes: (OFFileAttributes)attributes ofItemAtURL: (OFURL *)URL { OFURLHandler *URLHandler; if (URL == nil) @throw [OFInvalidArgumentException exception]; if ((URLHandler = [OFURLHandler handlerForURL: URL]) == nil) @throw [OFUnsupportedProtocolException exceptionWithURL: URL]; - [URLHandler setAttributes: attributes - ofItemAtURL: URL]; + [URLHandler setAttributes: attributes ofItemAtURL: URL]; } #ifdef OF_HAVE_FILES -- (void)setAttributes: (of_file_attributes_t)attributes +- (void)setAttributes: (OFFileAttributes)attributes ofItemAtPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); - [self setAttributes: attributes ofItemAtURL: [OFURL fileURLWithPath: path]]; - objc_autoreleasePoolPop(pool); } #endif - (bool)fileExistsAtURL: (OFURL *)URL @@ -425,11 +420,11 @@ objc_autoreleasePoolPop(pool); } #endif -- (OFArray OF_GENERIC(OFString *) *)contentsOfDirectoryAtURL: (OFURL *)URL +- (OFArray OF_GENERIC(OFURL *) *)contentsOfDirectoryAtURL: (OFURL *)URL { OFURLHandler *URLHandler; if (URL == nil) @throw [OFInvalidArgumentException exception]; @@ -442,13 +437,18 @@ #ifdef OF_HAVE_FILES - (OFArray OF_GENERIC(OFString *) *)contentsOfDirectoryAtPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); - OFArray OF_GENERIC(OFString *) *ret; + OFArray OF_GENERIC(OFURL *) *URLs; + OFMutableArray OF_GENERIC(OFString *) *ret; - ret = [self contentsOfDirectoryAtURL: [OFURL fileURLWithPath: path]]; + URLs = [self contentsOfDirectoryAtURL: [OFURL fileURLWithPath: path]]; + ret = [OFMutableArray arrayWithCapacity: URLs.count]; + + for (OFURL *URL in URLs) + [ret addObject: URL.lastPathComponent]; [ret retain]; objc_autoreleasePoolPop(pool); @@ -518,12 +518,11 @@ [self changeCurrentDirectoryPath: URL.fileSystemRepresentation]; objc_autoreleasePoolPop(pool); } -- (void)copyItemAtPath: (OFString *)source - toPath: (OFString *)destination +- (void)copyItemAtPath: (OFString *)source toPath: (OFString *)destination { void *pool = objc_autoreleasePoolPush(); [self copyItemAtURL: [OFURL fileURLWithPath: source] toURL: [OFURL fileURLWithPath: destination]]; @@ -530,17 +529,16 @@ objc_autoreleasePoolPop(pool); } #endif -- (void)copyItemAtURL: (OFURL *)source - toURL: (OFURL *)destination +- (void)copyItemAtURL: (OFURL *)source toURL: (OFURL *)destination { void *pool; OFURLHandler *URLHandler; - of_file_attributes_t attributes; - of_file_type_t type; + OFFileAttributes attributes; + OFFileAttributeType type; if (source == nil || destination == nil) @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); @@ -547,12 +545,11 @@ if ((URLHandler = [OFURLHandler handlerForURL: source]) == nil) @throw [OFUnsupportedProtocolException exceptionWithURL: source]; - if ([URLHandler copyItemAtURL: source - toURL: destination]) + if ([URLHandler copyItemAtURL: source toURL: destination]) return; if ([self fileExistsAtURL: destination]) @throw [OFCopyItemFailedException exceptionWithSourceURL: source @@ -568,22 +565,21 @@ errNo: e.errNo]; } type = attributes.fileType; - if ([type isEqual: of_file_type_directory]) { - OFArray *contents; + if ([type isEqual: OFFileTypeDirectory]) { + OFArray OF_GENERIC(OFURL *) *contents; @try { [self createDirectoryAtURL: destination]; @try { - of_file_attribute_key_t key = - of_file_attribute_key_posix_permissions; + OFFileAttributeKey key = OFFilePOSIXPermissions; OFNumber *permissions = [attributes objectForKey: key]; - of_file_attributes_t destinationAttributes; + OFFileAttributes destinationAttributes; if (permissions != nil) { destinationAttributes = [OFDictionary dictionaryWithObject: permissions forKey: key]; @@ -609,31 +605,27 @@ errNo: [e errNo]]; @throw e; } - for (OFString *item in contents) { + for (OFURL *item in contents) { void *pool2 = objc_autoreleasePoolPush(); - OFURL *sourceURL, *destinationURL; - - sourceURL = - [source URLByAppendingPathComponent: item]; - destinationURL = - [destination URLByAppendingPathComponent: item]; - - [self copyItemAtURL: sourceURL - toURL: destinationURL]; + OFURL *destinationURL = [destination + URLByAppendingPathComponent: + item.lastPathComponent]; + + [self copyItemAtURL: item toURL: destinationURL]; objc_autoreleasePoolPop(pool2); } - } else if ([type isEqual: of_file_type_regular]) { + } else if ([type isEqual: OFFileTypeRegular]) { size_t pageSize = [OFSystemInfo pageSize]; OFStream *sourceStream = nil; OFStream *destinationStream = nil; char *buffer; - buffer = of_alloc(1, pageSize); + buffer = OFAllocMemory(1, pageSize); @try { sourceStream = [[OFURLHandler handlerForURL: source] openItemAtURL: source mode: @"r"]; destinationStream = [[OFURLHandler handlerForURL: @@ -649,15 +641,14 @@ [destinationStream writeBuffer: buffer length: length]; } @try { - of_file_attribute_key_t key = - of_file_attribute_key_posix_permissions; + OFFileAttributeKey key = OFFilePOSIXPermissions; OFNumber *permissions = [attributes objectForKey: key]; - of_file_attributes_t destinationAttributes; + OFFileAttributes destinationAttributes; if (permissions != nil) { destinationAttributes = [OFDictionary dictionaryWithObject: permissions forKey: key]; @@ -682,13 +673,13 @@ @throw e; } @finally { [sourceStream close]; [destinationStream close]; - free(buffer); + OFFreeMemory(buffer); } - } else if ([type isEqual: of_file_type_symbolic_link]) { + } else if ([type isEqual: OFFileTypeSymbolicLink]) { @try { OFString *linkDestination = attributes.fileSymbolicLinkDestination; [self createSymbolicLinkAtURL: destination @@ -716,24 +707,20 @@ objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_FILES -- (void)moveItemAtPath: (OFString *)source - toPath: (OFString *)destination +- (void)moveItemAtPath: (OFString *)source toPath: (OFString *)destination { void *pool = objc_autoreleasePoolPush(); - [self moveItemAtURL: [OFURL fileURLWithPath: source] toURL: [OFURL fileURLWithPath: destination]]; - objc_autoreleasePoolPop(pool); } #endif -- (void)moveItemAtURL: (OFURL *)source - toURL: (OFURL *)destination +- (void)moveItemAtURL: (OFURL *)source toURL: (OFURL *)destination { void *pool; OFURLHandler *URLHandler; if (source == nil || destination == nil) @@ -744,12 +731,11 @@ if ((URLHandler = [OFURLHandler handlerForURL: source]) == nil) @throw [OFUnsupportedProtocolException exceptionWithURL: source]; @try { - if ([URLHandler moveItemAtURL: source - toURL: destination]) + if ([URLHandler moveItemAtURL: source toURL: destination]) return; } @catch (OFMoveItemFailedException *e) { if (e.errNo != EXDEV) @throw e; } @@ -759,12 +745,11 @@ exceptionWithSourceURL: source destinationURL: destination errNo: EEXIST]; @try { - [self copyItemAtURL: source - toURL: destination]; + [self copyItemAtURL: source toURL: destination]; } @catch (OFCopyItemFailedException *e) { [self removeItemAtURL: destination]; @throw [OFMoveItemFailedException exceptionWithSourceURL: source @@ -799,19 +784,16 @@ #ifdef OF_HAVE_FILES - (void)removeItemAtPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); - [self removeItemAtURL: [OFURL fileURLWithPath: path]]; - objc_autoreleasePoolPop(pool); } #endif -- (void)linkItemAtURL: (OFURL *)source - toURL: (OFURL *)destination +- (void)linkItemAtURL: (OFURL *)source toURL: (OFURL *)destination { void *pool = objc_autoreleasePoolPush(); OFURLHandler *URLHandler; if (source == nil || destination == nil) @@ -824,25 +806,21 @@ if (URLHandler == nil) @throw [OFUnsupportedProtocolException exceptionWithURL: source]; - [URLHandler linkItemAtURL: source - toURL: destination]; + [URLHandler linkItemAtURL: source toURL: destination]; objc_autoreleasePoolPop(pool); } #ifdef OF_FILE_MANAGER_SUPPORTS_LINKS -- (void)linkItemAtPath: (OFString *)source - toPath: (OFString *)destination +- (void)linkItemAtPath: (OFString *)source toPath: (OFString *)destination { void *pool = objc_autoreleasePoolPush(); - [self linkItemAtURL: [OFURL fileURLWithPath: source] toURL: [OFURL fileURLWithPath: destination]]; - objc_autoreleasePoolPop(pool); } #endif - (void)createSymbolicLinkAtURL: (OFURL *)URL @@ -857,25 +835,22 @@ URLHandler = [OFURLHandler handlerForURL: URL]; if (URLHandler == nil) @throw [OFUnsupportedProtocolException exceptionWithURL: URL]; - [URLHandler createSymbolicLinkAtURL: URL - withDestinationPath: target]; + [URLHandler createSymbolicLinkAtURL: URL withDestinationPath: target]; objc_autoreleasePoolPop(pool); } #ifdef OF_FILE_MANAGER_SUPPORTS_SYMLINKS - (void)createSymbolicLinkAtPath: (OFString *)path withDestinationPath: (OFString *)target { void *pool = objc_autoreleasePoolPush(); - [self createSymbolicLinkAtURL: [OFURL fileURLWithPath: path] withDestinationPath: target]; - objc_autoreleasePoolPop(pool); } #endif @end @@ -894,79 +869,74 @@ { } - (unsigned int)retainCount { - return OF_RETAIN_COUNT_MAX; + return OFMaxRetainCount; } @end @implementation OFDictionary (FileAttributes) - (unsigned long long)fileSize { - return [attributeForKeyOrException(self, of_file_attribute_key_size) + return [attributeForKeyOrException(self, OFFileSize) unsignedLongLongValue]; } -- (of_file_type_t)fileType +- (OFFileAttributeType)fileType { - return attributeForKeyOrException(self, of_file_attribute_key_type); + return attributeForKeyOrException(self, OFFileType); } - (unsigned long)filePOSIXPermissions { return [attributeForKeyOrException(self, - of_file_attribute_key_posix_permissions) unsignedLongValue]; -} - -- (unsigned long)filePOSIXUID -{ - return [attributeForKeyOrException(self, - of_file_attribute_key_posix_uid) unsignedLongValue]; -} - -- (unsigned long)filePOSIXGID -{ - return [attributeForKeyOrException(self, - of_file_attribute_key_posix_gid) unsignedLongValue]; -} - -- (OFString *)fileOwner -{ - return attributeForKeyOrException(self, of_file_attribute_key_owner); -} - -- (OFString *)fileGroup -{ - return attributeForKeyOrException(self, of_file_attribute_key_group); + OFFilePOSIXPermissions) unsignedLongValue]; +} + +- (unsigned long)fileOwnerAccountID +{ + return [attributeForKeyOrException(self, + OFFileOwnerAccountID) unsignedLongValue]; +} + +- (unsigned long)fileGroupOwnerAccountID +{ + return [attributeForKeyOrException(self, + OFFileGroupOwnerAccountID) unsignedLongValue]; +} + +- (OFString *)fileOwnerAccountName +{ + return attributeForKeyOrException(self, OFFileOwnerAccountName); +} + +- (OFString *)fileGroupOwnerAccountName +{ + return attributeForKeyOrException(self, OFFileGroupOwnerAccountName); } - (OFDate *)fileLastAccessDate { - return attributeForKeyOrException(self, - of_file_attribute_key_last_access_date); + return attributeForKeyOrException(self, OFFileLastAccessDate); } - (OFDate *)fileModificationDate { - return attributeForKeyOrException(self, - of_file_attribute_key_modification_date); + return attributeForKeyOrException(self, OFFileModificationDate); } - (OFDate *)fileStatusChangeDate { - return attributeForKeyOrException(self, - of_file_attribute_key_status_change_date); + return attributeForKeyOrException(self, OFFileStatusChangeDate); } - (OFDate *)fileCreationDate { - return attributeForKeyOrException(self, - of_file_attribute_key_creation_date); + return attributeForKeyOrException(self, OFFileCreationDate); } - (OFString *)fileSymbolicLinkDestination { - return attributeForKeyOrException(self, - of_file_attribute_key_symbolic_link_destination); + return attributeForKeyOrException(self, OFFileSymbolicLinkDestination); } @end