]> err.no Git - sope/blobdiff - sope-core/NGExtensions/FdExt.subproj/NSFileManager+Extensions.m
fixed -isAfternoon method
[sope] / sope-core / NGExtensions / FdExt.subproj / NSFileManager+Extensions.m
index 0e1e5e7f3a1b6a05db075792f47078a80bc81a46..5815f05386cbe8228d7fd85db7a8046d67d13d38 100644 (file)
@@ -1,7 +1,7 @@
 /*
-  Copyright (C) 2000-2003 SKYRIX Software AG
+  Copyright (C) 2000-2004 SKYRIX Software AG
 
-  This file is part of OGo
+  This file is part of OpenGroupware.org.
 
   OGo 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
@@ -18,7 +18,6 @@
   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
   02111-1307, USA.
 */
-// $Id$
 
 #include "NSFileManager+Extensions.h"
 #include "NGFileFolderInfoDataSource.h"
 
 @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 {