Permalink
Browse files

Fixed output path creation when multiple directories are missing. Closes

 #24.

The problem was in NSFileManager copyItemAtPath:toPath:error: which failed to copy an item when more two or more directories depth was missing at destination. This is properly handled now.
  • Loading branch information...
tomaz committed Jan 1, 2011
1 parent ea633da commit e8a1d9d83f2a2f920877199c6b6ff8e0f6fe1844
Showing with 7 additions and 0 deletions.
  1. +7 −0 Generating/GBOutputGenerator.m
@@ -68,6 +68,13 @@ - (BOOL)copyTemplateFilesToOutputPath:(NSError **)error {
}
}
+ // Create directory hierarchy minus the last one. This is necessary if more than one component is missing at destination path; copyItemAtPath:toPath:error would fail in such case. Note that we can't create the last directory as mentioned method request is that the destination doesn't exist!
+ NSString *createDestPath = [destPath stringByDeletingLastPathComponent];
+ if (![self.fileManager createDirectoryAtPath:createDestPath withIntermediateDirectories:YES attributes:nil error:error]) {
+ GBLogWarn(@"Failed creating directory '%@'!", createDestPath);
+ return NO;
+ }
+
// If there's no source file, there also no need to copy anything, so exit. In fact, copying would probably just result in errors.
if (![self.fileManager fileExistsAtPath:sourcePath]) {
GBLogDebug(@"No template file found at '%@', no need to copy.", sourceUserPath);

0 comments on commit e8a1d9d

Please sign in to comment.