From 7d0facc4243e3e6bf1734ebe6e3c2eb8b8fe17ed Mon Sep 17 00:00:00 2001 From: khanhduytran0 Date: Tue, 13 Aug 2024 21:53:10 +0700 Subject: [PATCH] Change how tmp files are stored To provide maximum compatibility, now guest app's tmp folder is just a symlink to that of LiveContainer. --- main.m | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/main.m b/main.m index b3cc8d4..67dfd66 100644 --- a/main.m +++ b/main.m @@ -239,11 +239,16 @@ static void overwriteExecPath(NSString *bundlePath) { NSProcessInfo.processInfo.processName = appBundle.infoDictionary[@"CFBundleExecutable"]; *_CFGetProgname() = NSProcessInfo.processInfo.processName.UTF8String; - // Overwrite home path + // Overwrite home and tmp path NSString *newHomePath = [NSString stringWithFormat:@"%@/Data/Application/%@", docPath, appBundle.infoDictionary[@"LCDataUUID"]]; + NSString *newTmpPath = [newHomePath stringByAppendingPathComponent:@"tmp"]; + remove(newTmpPath.UTF8String); + symlink(getenv("TMPDIR"), newTmpPath.UTF8String); + setenv("CFFIXED_USER_HOME", newHomePath.UTF8String, 1); setenv("HOME", newHomePath.UTF8String, 1); - setenv("TMPDIR", [@(getenv("TMPDIR")) stringByAppendingFormat:@"%@/tmp/", appBundle.infoDictionary[@"LCDataUUID"]].UTF8String, 1); + setenv("TMPDIR", newTmpPath.UTF8String, 1); + // Setup directories NSArray *dirList = @[@"Library/Caches", @"Documents", @"SystemData"]; for (NSString *dir in dirList) {