@@ -39,10 +39,11 @@ #import "OFURL.h" #import "OFURLHandler.h" #import "OFChangeCurrentDirectoryPathFailedException.h" #import "OFCopyItemFailedException.h" +#import "OFCreateDirectoryFailedException.h" #import "OFGetCurrentDirectoryPathFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFMoveItemFailedException.h" #import "OFOutOfMemoryException.h" @@ -318,10 +319,32 @@ if (!createParents) { [self createDirectoryAtURL: URL]; return; } + + /* + * Try blindly creating the directory first. + * + * The reason for this is that we might be sandboxed, so attempting to + * create any of the parent directories will fail, while creating the + * directory itself will work. + */ + if ([self directoryExistsAtURL: URL]) + return; + + @try { + [self createDirectoryAtURL: URL]; + return; + } @catch (OFCreateDirectoryFailedException *e) { + /* + * If we didn't fail because any of the parents is missing, + * there is no point in trying to create the parents. + */ + if ([e errNo] != ENOENT) + @throw e; + } components = [[URL URLEncodedPath] componentsSeparatedByString: @"/"]; for (OFString *component in components) { if (currentPath != nil)