X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/2e007a7245541ef16becc57493fa6159f2059ca4..6da09548ebbfc7b2412409492fe135a928ab0c64:/postinst.mm diff --git a/postinst.mm b/postinst.mm index a3269117..d96d624c 100644 --- a/postinst.mm +++ b/postinst.mm @@ -24,6 +24,44 @@ void Finish(const char *finish) { fclose(fout); } +static bool FixProtections() { + for (const char *path : (const char *[]) {"/var/lib", "/var/cache", "/var/stash"}) { + mkdir(path, 0755); + if (system([[NSString stringWithFormat:@"/usr/libexec/cydia/setnsfpn %s", path] UTF8String]) != 0) { + fprintf(stderr, "failed to setnsfpn %s\n", path); + return false; + } + } + return true; +} + +static void FixPermissions() { + DIR *stash(opendir("/var/stash")); + if (stash == NULL) + return; + + while (dirent *entry = readdir(stash)) { + const char *folder(entry->d_name); + if (strlen(folder) != 8) + continue; + if (strncmp(folder, "_.", 2) != 0) + continue; + + char path[1024]; + sprintf(path, "/var/stash/%s", folder); + + struct stat stat; + if (lstat(path, &stat) == -1) + continue; + if (!S_ISDIR(stat.st_mode)) + continue; + + chmod(path, 0755); + } + + closedir(stash); +} + #define APPLICATIONS "/Applications" static bool FixApplications() { char target[1024]; @@ -98,6 +136,10 @@ int main(int argc, const char *argv[]) { NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]); + if (kCFCoreFoundationVersionNumber >= 1000) + if (!FixProtections()) + return 1; + size_t size; sysctlbyname("kern.osversion", NULL, &size, NULL, 0); char *osversion = new char[size]; @@ -126,6 +168,12 @@ int main(int argc, const char *argv[]) { CydiaWriteSources(); + #define OldCache_ "/var/root/Library/Caches/com.saurik.Cydia" + if (access(OldCache_, F_OK) == 0) + system("rm -rf " OldCache_); + + FixPermissions(); + if (FixApplications()) Finish("restart");