Skip to content

Commit b156a93

Browse files
committed
Merge branch 'master' of https://github.com/sveinbjornt/Platypus
2 parents 2e27df3 + cefe970 commit b156a93

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

Shared/NSFileManager+TempFiles.m

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,18 @@ - (NSString *)createTempFileNamed:(NSString *)fileName withContents:(NSString *)
4141
// http://cocoawithlove.com/2009/07/temporary-files-and-folders-in-cocoa.html
4242

4343
NSString *tmpFileNameTemplate = fileName ? fileName : @"tmp_file_platypus_macos.XXXXXX";
44+
// Allow user to override the temporary directory by setting the TMPDIR environment variable
4445
NSString *tmpDir = NSTemporaryDirectory();
45-
if (!tmpDir) {
46-
NSLog(@"NSTemporaryDirectory() returned nil");
47-
return nil;
46+
char *tmpdir_cstring = getenv("TMPDIR");
47+
if (tmpdir_cstring != NULL && strlen(tmpdir_cstring) > 0) {
48+
tmpDir = [NSString stringWithUTF8String:tmpdir_cstring];
49+
} else {
50+
if (!tmpDir) {
51+
NSLog(@"NSTemporaryDirectory() returned nil");
52+
return nil;
53+
}
4854
}
49-
55+
5056
NSString *tempFileTemplate = [tmpDir stringByAppendingPathComponent:tmpFileNameTemplate];
5157
const char *tempFileTemplateCString = [tempFileTemplate fileSystemRepresentation];
5258
char *tempFileNameCString = (char *)malloc(strlen(tempFileTemplateCString) + 1);

Shared/PlatypusAppSpec.m

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,17 @@ - (BOOL)create {
260260
// .app bundle
261261
// Get temporary directory, make sure it's kosher. Apparently NSTemporaryDirectory() can return nil
262262
// See http://www.cocoadev.com/index.pl?NSTemporaryDirectory
263+
// Allow user to override the temporary directory by setting the TMPDIR environment variable
263264
NSString *tmpPath = NSTemporaryDirectory();
264-
if (tmpPath == nil) {
265+
char *tmpdir_cstring = getenv("TMPDIR");
266+
if (tmpdir_cstring != NULL && strlen(tmpdir_cstring) > 0) {
267+
tmpPath = [NSString stringWithUTF8String:tmpdir_cstring];
268+
} else {
269+
if (tmpPath == nil) {
265270
tmpPath = @"/tmp/"; // Fallback, just in case
271+
}
266272
}
267-
273+
268274
// Make sure we can write to temp path
269275
if ([FILEMGR isWritableFileAtPath:tmpPath] == NO) {
270276
_error = [NSString stringWithFormat:@"Could not write to the temp directory '%@'.", tmpPath];
@@ -409,7 +415,7 @@ - (BOOL)create {
409415
options:0
410416
error:nil];
411417
if (!infoData || ![infoData writeToFile:infoPlistPath atomically:YES]) {
412-
_error = @"Error writing Info.plist";
418+
_error = [NSString stringWithFormat:@"Error writing Info.plist: '%@'.", infoPlistPath];
413419
return NO;
414420
}
415421

0 commit comments

Comments
 (0)