-
Notifications
You must be signed in to change notification settings - Fork 11
Extract templates to files for development #24
Extract templates to files for development #24
Conversation
@@ -8,202 +8,184 @@ | |||
|
|||
#import "VOKTemplateModel.h" | |||
|
|||
#import <mach-o/getsect.h> | |||
#import <mach-o/ldsyms.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, this oughta be good.
Also added more comments and logging of a couple error cases, and updated the binary.
strcpy(tempDirectoryNameCString, tempDirectoryTemplateCString); | ||
|
||
// Have the system attempt to create a directory from the template. | ||
char *result = mkdtemp(tempDirectoryNameCString); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the advantage of using mkdtemp
instead of just using the NSFileManager
to create a directory which you then delete later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From http://www.cocoawithlove.com/2009/07/temporary-files-and-folders-in-cocoa.html (and I've added that URL in the docu-comment above this function):
To avoid concurrency issues (race conditions), you need to choose a name for any file or directory placed directly in the temporary directory that is unique but which also can't be stolen by another process between choosing the name and creating/opening the file or directory. Even though NSTemporaryDirectory() is unique for each user, you still must avoid potential conflicts within the user's account.
To do this, we use the POSIX function mkstemp for files and mkdtemp for directories. The former will return an already open file descriptor for the file and the latter will have already created the directory for us.
Note that this is much less of a thing on iOS because of sandboxing—for a given iOS app, the filesystem the app sees pretty much belongs entirely and solely to the app, so there's much less concern about what a malicious app sharing the filesystem might be able to do.
|
I've rewritten this so that:
I'd kind of like to expose those two encapsulations as optional subspecs of the Cat2Cat cocoapod so that other utilities can use them, but that can wait for later (or maybe they should be their own cocoapods). |
… in each template file.
* Load the zip archive that's been embedded into the running mach-o binary (in the __c2c_tmplt_zip section | ||
* of the __TEXT segment, by adding the flags: | ||
* -sectcreate __TEXT __c2c_tmplt_zip "${TARGET_BUILD_DIR}/template.zip" | ||
* to the "Other Linker Flags" build setting) to a temporary directory. (The template.zip file is created by |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per your comments, is this still being extracted to a temp directory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
D'oh.
I like this strategy. I would definitely vote separate pod rather than making them subspecs of this utility, though - they're something that helps this be more efficient, but it's not super duper related to Cat2Cat itself. Let me know if you want me to make you a repo for that. |
Yes, please. Maybe something like |
Done! I added you as a maintainer on that one. |
( 🐐 , 🐐 , 🐐 ) |
Extract templates to files for development
@vokal-isaac This doesn't need a version tag or a |
Correct. At a minimum, I'd want to do the split out of the new pod, but even then I'm not sure it makes sense to push a new version, as this produces identical output and changes nothing from the consumer standpoint. It's really a dev side improvement. |
👍 thanks! |
A working (as in produces identical output on all four sample projects) version of Cat2Cat where, for development, the templates are individual
.mustache
files that can be edited easily (rather than string constants in code). At build time, the templates directory is zipped and the zip file is embedded (by the linker) into the Cat2Cat executable. At runtime, Cat2Cat loads the embedded zip data and uses the template files contained in it to render the output.@vokal/ios-developers Code review please?