Posts

Post marked as solved
7 Replies
i finally found the actual answer to the TMPDIR content deletion behavior after observing my un-accessed 3-day old files in TMPDIR getting deleted at 3:35am. it's using a different mechanism from the /tmp/ directory. and if you don't want your per-user files to get deleted and still want it in /var/folders/ (and don't want to use the home directory ~/Library/Caches/), you might want to consider using the "cache" (DARWIN_USER_CACHE_DIR) directory instead. "3:35am" and "$TMPDIR" were mentioned in the page below. http://www.mobileread.mobi/forums/showthread.php?t=273999 "on Mac OS X, there is a dirhelper daemon that looks for files not accessed within 3 days inside the official temp directory and will delete them even if the app using them is still running." the dirhelper daemon runs at 3:35am and deletes files that didn't not get accessed for 3 days. /System/Library/LaunchDaemons/com.apple.bsd.dirhelper.plist % getconf DARWIN_USER_TEMP_DIR /var/folders/xx/xxxx_xxxx/T/ % getconf DARWIN_USER_CACHE_DIR /var/folders/xx/xxxx_xxxx/C/ % man confstr ... _CS_DARWIN_USER_TEMP_DIR Provides the path to a user's temporary items directory. The directory will be created it if does not already exist. This directory is created with access permissions of 0700 and restricted by the umask(2) of the calling process and is a good location for temporary files. By default, files in this location may be cleaned (removed) by the system if they are not accessed in 3 days. _CS_DARWIN_USER_CACHE_DIR Provides the path to the user's cache directory. The directory will be created if it does not already exist. This directory is created with access permissions of 0700 and restricted by the umask(2) of the calling process and is a good location for user cache data as it will not be automatically cleaned by the system. Files in this location will be removed during safe boot. ... % cat confstr.c // cc confstr.c -o confstr -mmacosx-version-min=10.11 -arch x86_64 -arch arm64 #include <unistd.h> #include <stdio.h> #include <sys/syslimits.h> int main() { char buf[PATH_MAX]; size_t len = PATH_MAX; size_t s = confstr(_CS_DARWIN_USER_TEMP_DIR, buf, len); printf("_CS_DARWIN_USER_TEMP_DIR(len:%d): %s\n", (int)s, buf); s = confstr(_CS_DARWIN_USER_CACHE_DIR, buf, len); printf("_CS_DARWIN_USER_CACHE_DIR(len:%d): %s\n", (int)s, buf); return 0; } % ./confstr _CS_DARWIN_USER_TEMP_DIR(len:50): /var/folders/xx/xxxx_xxxx/T/ _CS_DARWIN_USER_CACHE_DIR(len:50): /var/folders/xx/xxxx_xxxx/C/
Post not yet marked as solved
1 Replies
looks like NSApplicationActivationPolicyRegular and activateIgnoringOtherApps: were missing according to https://github.com/rgl/minimal-cocoa-app [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; dispatch_async(dispatch_get_main_queue(), ^{ [NSApp activateIgnoringOtherApps:YES]; }); here is the updated code: // cc -o min-cocoa min-cocoa.m -framework Cocoa #import <Cocoa/Cocoa.h> int main(int argc, const char * argv[]) { @autoreleasepool { [NSApplication sharedApplication]; id menubar = [NSMenu new]; id appMenuItem = [NSMenuItem new]; [menubar addItem:appMenuItem]; [NSApp setMainMenu:menubar]; id appMenu = [NSMenu new]; id appName = [[NSProcessInfo processInfo] processName]; id quitTitle = [@"Quit " stringByAppendingString:appName]; id quitMenuItem = [[NSMenuItem alloc] initWithTitle:quitTitle action:@selector(terminate:) keyEquivalent:@"q"] ; [appMenu addItem:quitMenuItem]; [appMenuItem setSubmenu:appMenu]; id window = [[NSWindow alloc] initWithContentRect:NSMakeRect(10, 10, 200, 200) styleMask:NSWindowStyleMaskTitled backing:NSBackingStoreBuffered defer:NO]; [window setTitle:appName]; [window cascadeTopLeftFromPoint:NSMakePoint(20,20)]; [window makeKeyAndOrderFront:nil]; [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; dispatch_async(dispatch_get_main_queue(), ^{ [NSApp activateIgnoringOtherApps:YES]; }); [NSApp run]; } return 0; }