diff options
-rwxr-xr-x | Library/move.sh | 9 | ||||
-rw-r--r-- | MobileCydia.mm | 5 | ||||
-rw-r--r-- | postinst.mm | 50 |
3 files changed, 61 insertions, 3 deletions
diff --git a/Library/move.sh b/Library/move.sh index 7e737e3..54750cd 100755 --- a/Library/move.sh +++ b/Library/move.sh @@ -20,8 +20,13 @@ function df_() { function mv_() { src=$1 - mkdir -p /var/stash - /usr/libexec/cydia/setnsfpn /var/stash + if [[ ! -e /var/stash ]]; then + mkdir -p /var/db/stash + /usr/libexec/cydia/setnsfpn /var/db/stash + ln -s -t /var /var/db/stash + elif [[ -d /var/stash ]]; then + /usr/libexec/cydia/setnsfpn /var/stash + fi tmp=$(mktemp -d /var/stash/_.XXXXXX) dst=${tmp}/${src##*/} diff --git a/MobileCydia.mm b/MobileCydia.mm index 49b74f6..e491c73 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -3157,6 +3157,7 @@ struct PackageNameOrdering : bool user = false; bool _private = false; bool stash = false; + bool dbstash = false; bool dsstore = false; bool repository = [[self section] isEqualToString:@"Repositories"]; @@ -3171,6 +3172,8 @@ struct PackageNameOrdering : _private = true; else if (!stash && [file isEqualToString:@"/var/stash"]) stash = true; + else if (!dbstash && [file isEqualToString:@"/var/db/stash"]) + dbstash = true; else if (!dsstore && [file hasSuffix:@"/.DS_Store"]) dsstore = true; @@ -3183,6 +3186,8 @@ struct PackageNameOrdering : [warnings addObject:[NSString stringWithFormat:UCLocalize("FILES_INSTALLED_TO"), @"/private"]]; if (stash) [warnings addObject:[NSString stringWithFormat:UCLocalize("FILES_INSTALLED_TO"), @"/var/stash"]]; + if (dbstash) + [warnings addObject:[NSString stringWithFormat:UCLocalize("FILES_INSTALLED_TO"), @"/var/db/stash"]]; if (dsstore) [warnings addObject:[NSString stringWithFormat:UCLocalize("FILES_INSTALLED_TO"), @".DS_Store"]]; } diff --git a/postinst.mm b/postinst.mm index c67cce5..e5658d2 100644 --- a/postinst.mm +++ b/postinst.mm @@ -28,14 +28,62 @@ 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() { - for (const char *path : (const char *[]) {"/var/lib", "/var/cache", "/var/stash"}) { + for (const char *path : (const char *[]) {"/var/lib", "/var/cache"}) { mkdir(path, 0755); if (!setnsfpn(path)) { fprintf(stderr, "failed to setnsfpn %s\n", path); return false; } } + + if (!MoveStash()) { + fprintf(stderr, "failed to move stash\n"); + return false; + } + return true; } |