2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "NSFileManager+Extensions.h"
23 #include "NGFileFolderInfoDataSource.h"
24 #include <EOControl/EOGlobalID.h>
27 @interface NSFileManagerGlobalID : EOGlobalID < NSCopying >
34 // TODO: support -lastException
35 // TODO: add stuff like -dictionaryAtPath:, -arrayAtPath:, -propertyListAtPath:
37 @implementation NSFileManager(ExtendedFileManagerImp)
41 - (BOOL)createDirectoriesAtPath:(NSString *)_p attributes:(NSDictionary *)_a {
48 if ([self fileExistsAtPath:_p isDirectory:&isDir])
51 pc = [_p pathComponents];
52 if ((count = [pc count]) == 0)
55 for (i = 0; i < count; i++) {
62 fp = [NSString pathWithComponents:[pc subarrayWithRange:r]];
63 if ([self fileExistsAtPath:fp isDirectory:&isDir]) {
64 if (!isDir) /* exists, but is a file */
69 if (![self createDirectoryAtPath:fp attributes:_a])
70 /* failed to create */
76 /* path modifications */
78 - (NSString *)standardizePath:(NSString *)_path {
79 if (![_path isAbsolutePath])
80 _path = [[self currentDirectoryPath] stringByAppendingPathComponent:_path];
82 return [_path stringByStandardizingPath];
84 - (NSString *)resolveSymlinksInPath:(NSString *)_path {
85 return [_path stringByResolvingSymlinksInPath];
87 - (NSString *)expandTildeInPath:(NSString *)_path {
88 return [_path stringByExpandingTildeInPath];
93 - (BOOL)supportsVersioningAtPath:(NSString *)_path {
96 - (BOOL)supportsLockingAtPath:(NSString *)_path {
99 - (BOOL)supportsFolderDataSourceAtPath:(NSString *)_path {
103 - (BOOL)supportsFeature:(NSString *)_featureURI atPath:(NSString *)_path {
104 if ([_featureURI isEqualToString:NGFileManagerFeature_DataSources])
112 - (BOOL)writeContents:(NSData *)_content atPath:(NSString *)_path {
113 return [_content writeToFile:_path atomically:YES];
118 - (EOGlobalID *)globalIDForPath:(NSString *)_path {
119 NSFileManagerGlobalID *gid;
121 _path = [self standardizePath:_path];
123 gid = [[NSFileManagerGlobalID alloc] init];
124 gid->path = [_path copy];
125 return [gid autorelease];
127 - (NSString *)pathForGlobalID:(EOGlobalID *)_gid {
128 NSFileManagerGlobalID *gid;
130 if (![_gid isKindOfClass:[NSFileManagerGlobalID class]])
131 /* not a gid we can handle ... */
134 gid = (NSFileManagerGlobalID *)_gid;
138 /* datasources (work on folders) */
140 - (EODataSource *)dataSourceAtPath:(NSString *)_path {
141 return [[[NGFileFolderInfoDataSource alloc] initWithFolderPath:_path]
145 - (EODataSource *)dataSource {
146 return [self dataSourceAtPath:[self currentDirectoryPath]];
151 - (BOOL)supportsTrashFolderAtPath:(NSString *)_path {
154 - (NSString *)trashFolderForPath:(NSString *)_path {
158 - (BOOL)trashFileAtPath:(NSString *)_path handler:(id)_handler {
159 // TODO: support trashfolder on MacOSX ?
163 @end /* NSFileManager(ExtendedFileManagerImp) */
165 @implementation NSFileManagerGlobalID
168 [self->path release];
174 - (id)copyWithZone:(NSZone *)_zone {
175 /* global IDs are immutable, so we can return an retained object ... */
176 return [self retain];
181 - (NSString *)description {
182 NSMutableString *ms = [NSMutableString stringWithCapacity:32];
184 [ms appendFormat:@"<0x%08X[%@]", self, NSStringFromClass([self class])];
185 [ms appendFormat:@" path=%@", self->path];
186 [ms appendString:@">"];
190 @end /* NSFileManagerGlobalID */