File tree Expand file tree Collapse file tree 2 files changed +18
-6
lines changed
Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Original file line number Diff line number Diff 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 );
Original file line number Diff line number Diff 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];
You can’t perform that action at this time.
0 commit comments