]> err.no Git - sope/blobdiff - sope-core/NGExtensions/FdExt.subproj/NSFileManager+Extensions.m
Drop apache 1 build-dependency
[sope] / sope-core / NGExtensions / FdExt.subproj / NSFileManager+Extensions.m
index 0e1e5e7f3a1b6a05db075792f47078a80bc81a46..aa142299d411a1bc4105c87511e48c2e5566ae71 100644 (file)
@@ -1,28 +1,27 @@
 /*
-  Copyright (C) 2000-2003 SKYRIX Software AG
+  Copyright (C) 2000-2005 SKYRIX Software AG
 
-  This file is part of OGo
+  This file is part of SOPE.
 
-  OGo is free software; you can redistribute it and/or modify it under
+  SOPE is free software; you can redistribute it and/or modify it under
   the terms of the GNU Lesser General Public License as published by the
   Free Software Foundation; either version 2, or (at your option) any
   later version.
 
-  OGo is distributed in the hope that it will be useful, but WITHOUT ANY
+  SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
   WARRANTY; without even the implied warranty of MERCHANTABILITY or
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
   License for more details.
 
   You should have received a copy of the GNU Lesser General Public
-  License along with OGo; see the file COPYING.  If not, write to the
+  License along with SOPE; see the file COPYING.  If not, write to the
   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
   02111-1307, USA.
 */
-// $Id$
 
 #include "NSFileManager+Extensions.h"
 #include "NGFileFolderInfoDataSource.h"
-#include <EOControl/EOGlobalID.h>
+#import <EOControl/EOGlobalID.h>
 #include "common.h"
 
 @interface NSFileManagerGlobalID : EOGlobalID < NSCopying >
 
 @implementation NSFileManager(ExtendedFileManagerImp)
 
+/* directories */
+
+- (BOOL)createDirectoriesAtPath:(NSString *)_p attributes:(NSDictionary *)_a {
+  unsigned i, count;
+  NSArray *pc;
+  BOOL    isDir;
+  
+  if ([_p length] == 0)
+    return NO;
+  if ([self fileExistsAtPath:_p isDirectory:&isDir])
+    return isDir;
+  
+  pc = [_p pathComponents];
+  if ((count = [pc count]) == 0)
+    return YES;
+  
+  for (i = 0; i < count; i++) {
+    NSString *fp;
+    NSRange  r;
+    
+    r.location = 0;
+    r.length   = i + 1;
+    
+    fp = [NSString pathWithComponents:[pc subarrayWithRange:r]];
+    if ([self fileExistsAtPath:fp isDirectory:&isDir]) {
+      if (!isDir) /* exists, but is a file */
+        return NO;
+      continue;
+    }
+    
+    if (![self createDirectoryAtPath:fp attributes:_a])
+      /* failed to create */
+      return NO;
+  }
+  return YES;
+}
+
 /* path modifications */
 
 - (NSString *)standardizePath:(NSString *)_path {
 /* datasources (work on folders) */
 
 - (EODataSource *)dataSourceAtPath:(NSString *)_path {
-  return
-    [[[NGFileFolderInfoDataSource alloc] initWithFolderPath:_path] autorelease];
+  return [[[NGFileFolderInfoDataSource alloc] initWithFolderPath:_path] 
+           autorelease];
 }
 
 - (EODataSource *)dataSource {
 - (NSString *)description {
   NSMutableString *ms = [NSMutableString stringWithCapacity:32];
   
-  [ms appendFormat:@"<0x%08X[%@]", self, NSStringFromClass([self class])];
+  [ms appendFormat:@"<0x%p[%@]", self, NSStringFromClass([self class])];
   [ms appendFormat:@" path=%@", self->path];
   [ms appendString:@">"];
   return ms;