@@ -158,12 +158,12 @@ } + (instancetype)fileWithPath: (OFString*)path mode: (OFString*)mode { - return [[[self alloc] initWithPath: path - mode: mode] autorelease]; + return [[(OFFile*)[self alloc] initWithPath: path + mode: mode] autorelease]; } + (instancetype)fileWithFileDescriptor: (int)filedescriptor { return [[[self alloc] @@ -242,12 +242,11 @@ DIR_MODE)) #else if (_wmkdir([path UTF16String])) #endif @throw [OFCreateDirectoryFailedException - exceptionWithClass: self - path: path]; + exceptionWithPath: path]; } + (void)createDirectoryAtPath: (OFString*)path createParents: (bool)createParents { @@ -296,13 +295,12 @@ DIR *dir; struct dirent *dirent; if ((dir = opendir([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) == NULL) - @throw [OFOpenFileFailedException exceptionWithClass: self - path: path - mode: @"r"]; + @throw [OFOpenFileFailedException exceptionWithPath: path + mode: @"r"]; @try { while ((dirent = readdir(dir)) != NULL) { void *pool = objc_autoreleasePoolPush(); OFString *file; @@ -328,13 +326,12 @@ path = [path stringByAppendingString: @"\\*"]; if ((handle = FindFirstFileW([path UTF16String], &fd)) == INVALID_HANDLE_VALUE) - @throw [OFOpenFileFailedException exceptionWithClass: self - path: path - mode: @"r"]; + @throw [OFOpenFileFailedException exceptionWithPath: path + mode: @"r"]; @try { do { void *pool2 = objc_autoreleasePoolPush(); OFString *file; @@ -366,12 +363,11 @@ if (chdir([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) #else if (_wchdir([path UTF16String])) #endif @throw [OFChangeDirectoryFailedException - exceptionWithClass: self - path: path]; + exceptionWithPath: path]; } #ifdef OF_HAVE_CHMOD + (void)changeModeOfFileAtPath: (OFString*)path mode: (mode_t)mode @@ -380,13 +376,12 @@ if (chmod([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], mode)) # else if (_wchmod([path UTF16String], mode)) # endif @throw [OFChangeFileModeFailedException - exceptionWithClass: self - path: path - mode: mode]; + exceptionWithPath: path + mode: mode]; } #endif + (off_t)sizeOfFileAtPath: (OFString*)path { @@ -399,13 +394,12 @@ struct _stat s; if (_wstat([path UTF16String], &s) == -1) #endif /* FIXME: Maybe use another exception? */ - @throw [OFOpenFileFailedException exceptionWithClass: self - path: path - mode: @"r"]; + @throw [OFOpenFileFailedException exceptionWithPath: path + mode: @"r"]; return s.st_size; } + (OFDate*)modificationDateOfFileAtPath: (OFString*)path @@ -419,13 +413,12 @@ struct _stat s; if (_wstat([path UTF16String], &s) == -1) #endif /* FIXME: Maybe use another exception? */ - @throw [OFOpenFileFailedException exceptionWithClass: self - path: path - mode: @"r"]; + @throw [OFOpenFileFailedException exceptionWithPath: path + mode: @"r"]; /* FIXME: We could be more precise on some OSes */ return [OFDate dateWithTimeIntervalSince1970: s.st_mtime]; } @@ -436,29 +429,27 @@ { uid_t uid = -1; gid_t gid = -1; if (owner == nil && group == nil) - @throw [OFInvalidArgumentException exceptionWithClass: self - selector: _cmd]; + @throw [OFInvalidArgumentException exception]; # ifdef OF_HAVE_THREADS if (!of_mutex_lock(&mutex)) - @throw [OFLockFailedException exceptionWithClass: self]; + @throw [OFLockFailedException exception]; @try { # endif if (owner != nil) { struct passwd *passwd; if ((passwd = getpwnam([owner cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) == NULL) @throw [OFChangeFileOwnerFailedException - exceptionWithClass: self - path: path - owner: owner - group: group]; + exceptionWithPath: path + owner: owner + group: group]; uid = passwd->pw_uid; } if (group != nil) { @@ -465,32 +456,29 @@ struct group *group_; if ((group_ = getgrnam([group cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) == NULL) @throw [OFChangeFileOwnerFailedException - exceptionWithClass: self - path: path - owner: owner - group: group]; + exceptionWithPath: path + owner: owner + group: group]; gid = group_->gr_gid; } # ifdef OF_HAVE_THREADS } @finally { if (!of_mutex_unlock(&mutex)) - @throw [OFUnlockFailedException - exceptionWithClass: self]; + @throw [OFUnlockFailedException exception]; } # endif if (chown([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], uid, gid)) @throw [OFChangeFileOwnerFailedException - exceptionWithClass: self - path: path - owner: owner - group: group]; + exceptionWithPath: path + owner: owner + group: group]; } #endif + (void)copyFileAtPath: (OFString*)source toPath: (OFString*)destination @@ -510,12 +498,12 @@ override = [self fileExistsAtPath: destination]; pageSize = [OFSystemInfo pageSize]; if ((buffer = malloc(pageSize)) == NULL) - @throw [OFOutOfMemoryException exceptionWithClass: self - requestedSize: pageSize]; + @throw [OFOutOfMemoryException + exceptionWithRequestedSize: pageSize]; @try { sourceFile = [OFFile fileWithPath: source mode: @"rb"]; destinationFile = [OFFile fileWithPath: destination @@ -566,13 +554,12 @@ [destination cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) #else if (_wrename([source UTF16String], [destination UTF16String])) #endif @throw [OFRenameFileFailedException - exceptionWithClass: self - sourcePath: source - destinationPath: destination]; + exceptionWithSourcePath: source + destinationPath: destination]; objc_autoreleasePoolPop(pool); } + (void)deleteFileAtPath: (OFString*)path @@ -580,12 +567,11 @@ #ifndef _WIN32 if (unlink([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) #else if (_wunlink([path UTF16String])) #endif - @throw [OFDeleteFileFailedException exceptionWithClass: self - path: path]; + @throw [OFDeleteFileFailedException exceptionWithPath: path]; } + (void)deleteDirectoryAtPath: (OFString*)path { #ifndef _WIN32 @@ -592,12 +578,11 @@ if (rmdir([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) #else if (_wrmdir([path UTF16String])) #endif @throw [OFDeleteDirectoryFailedException - exceptionWithClass: self - path: path]; + exceptionWithPath: path]; } #ifdef OF_HAVE_LINK + (void)linkFileAtPath: (OFString*)source toPath: (OFString*)destination @@ -610,13 +595,13 @@ nil]; } if (link([source cStringWithEncoding: OF_STRING_ENCODING_NATIVE], [destination cStringWithEncoding: OF_STRING_ENCODING_NATIVE]) != 0) - @throw [OFLinkFailedException exceptionWithClass: self - sourcePath: source - destinationPath: destination]; + @throw [OFLinkFailedException + exceptionWithSourcePath: source + destinationPath: destination]; objc_autoreleasePoolPop(pool); } #endif @@ -633,13 +618,12 @@ } if (symlink([source cStringWithEncoding: OF_STRING_ENCODING_NATIVE], [destination cStringWithEncoding: OF_STRING_ENCODING_NATIVE]) != 0) @throw [OFSymlinkFailedException - exceptionWithClass: self - sourcePath: source - destinationPath: destination]; + exceptionWithSourcePath: source + destinationPath: destination]; objc_autoreleasePoolPop(pool); } #endif @@ -662,25 +646,22 @@ @try { int flags; if ((flags = parse_mode([mode UTF8String])) == -1) - @throw [OFInvalidArgumentException - exceptionWithClass: [self class] - selector: _cmd]; + @throw [OFInvalidArgumentException exception]; #ifndef _WIN32 if ((_fd = open([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], flags, DEFAULT_MODE)) == -1) #else if ((_fd = _wopen([path UTF16String], flags, DEFAULT_MODE)) == -1) #endif @throw [OFOpenFileFailedException - exceptionWithClass: [self class] - path: path - mode: mode]; + exceptionWithPath: path + mode: mode]; } @catch (id e) { [self release]; @throw e; } @@ -709,13 +690,12 @@ { ssize_t ret; if (_fd == -1 || _atEndOfStream || (ret = read(_fd, buffer, length)) < 0) - @throw [OFReadFailedException exceptionWithClass: [self class] - stream: self - requestedLength: length]; + @throw [OFReadFailedException exceptionWithStream: self + requestedLength: length]; if (ret == 0) _atEndOfStream = true; return ret; @@ -723,23 +703,21 @@ - (void)lowlevelWriteBuffer: (const void*)buffer length: (size_t)length { if (_fd == -1 || _atEndOfStream || write(_fd, buffer, length) < length) - @throw [OFWriteFailedException exceptionWithClass: [self class] - stream: self - requestedLength: length]; + @throw [OFWriteFailedException exceptionWithStream: self + requestedLength: length]; } - (void)lowlevelSeekToOffset: (off_t)offset whence: (int)whence { if (lseek(_fd, offset, whence) == -1) - @throw [OFSeekFailedException exceptionWithClass: [self class] - stream: self - offset: offset - whence: whence]; + @throw [OFSeekFailedException exceptionWithStream: self + offset: offset + whence: whence]; } - (int)fileDescriptorForReading { return _fd;