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);
+static bool setnsfpn(const char *path) {
+ return system([[NSString stringWithFormat:@"/usr/libexec/cydia/setnsfpn %s", path] UTF8String]) == 0;
+}
+
+static bool MoveStash() {
+ struct stat stat;
+
+ if (lstat("/var/stash", &stat) == -1)
+ return errno == ENOENT;
+ else if (S_ISLNK(stat.st_mode))
+ return true;
+ else if (!S_ISDIR(stat.st_mode))
+ return false;
+
+ if (lstat("/var/db/stash", &stat) == -1) {
+ if (errno == ENOENT)
+ goto move;
+ else return false;
+ } else if (S_ISLNK(stat.st_mode))
+ // XXX: this is fixable
+ return false;
+ else if (!S_ISDIR(stat.st_mode))
+ return false;
+ else {
+ if (!setnsfpn("/var/db/stash"))
return false;
- }
+ if (system("mv -t /var/stash /var/db/stash/*") != 0)
+ return false;
+ if (rmdir("/var/db/stash") == -1)
+ return false;
+ } move:
+
+ if (!setnsfpn("/var/stash"))
+ return false;
+
+ if (rename("/var/stash", "/var/db/stash") == -1)
+ return false;
+ if (symlink("/var/db/stash", "/var/stash") != -1)
+ return true;
+ if (rename("/var/db/stash", "/var/stash") != -1)
+ return false;
+
+ fprintf(stderr, "/var/stash misplaced -- DO NOT REBOOT\n");
+ return false;
+}
+
+static bool FixProtections() {
+ const char *path("/var/lib");
+ mkdir(path, 0755);
+ if (!setnsfpn(path)) {
+ fprintf(stderr, "failed to setnsfpn %s\n", path);
+ return false;
}
+
return true;
}
NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
- if (kCFCoreFoundationVersionNumber >= 1000)
+ bool restart(false);
+
+ if (kCFCoreFoundationVersionNumber >= 1000) {
if (!FixProtections())
return 1;
+ if (MoveStash())
+ restart = true;
+ else {
+ fprintf(stderr, "failed to move stash\n");
+ return 1;
+ }
+ }
size_t size;
sysctlbyname("kern.osversion", NULL, &size, NULL, 0);
system("chown -R 501.501 " NewCache_ "/lists");
}
- if (access(NewCache_ "/metadata.cb0", F_OK) != 0 && errno == ENOENT)
- if (access("/var/lib/cydia/metadata.cb0", F_OK) == 0) {
- system("mv /var/lib/cydia/metadata.cb0 " NewCache_);
- chown(NewCache_ "/metadata.cb0", 501, 501);
- }
+ #define OldLibrary_ "/var/lib/cydia"
+
+ #define NewLibrary_ "/var/mobile/Library/Cydia"
+ system("cd /; su -c 'mkdir -p " NewLibrary_ "' mobile");
+
+ #define Cytore_ "/metadata.cb0"
+
+ if (access(NewLibrary_ Cytore_, F_OK) != 0 && errno == ENOENT) {
+ if (access(NewCache_ Cytore_, F_OK) == 0)
+ system("mv -f " NewCache_ Cytore_ " " NewLibrary_);
+ else if (access(OldLibrary_ Cytore_, F_OK) == 0)
+ system("mv -f " OldLibrary_ Cytore_ " " NewLibrary_);
+ chown(NewLibrary_ Cytore_, 501, 501);
+ }
FixPermissions();
- if (FixApplications())
+ restart |= FixApplications();
+
+ if (restart)
Finish("restart");
[pool release];