diff options
author | Jay Freeman (saurik) <saurik@saurik.com> | 2015-06-27 01:42:19 -0700 |
---|---|---|
committer | Jay Freeman (saurik) <saurik@saurik.com> | 2015-06-27 01:42:19 -0700 |
commit | e40620ab668eb5ba83806b13eebf91f7defb3453 (patch) | |
tree | ee7ab8cbd0c4dfb9647167c53dfa994aeb95ca36 /MobileCydia.mm | |
parent | 64edd9dfbc798337d33d3b070a1174c9a1b09eb9 (diff) |
Drop sysroot dependency on coreutils by owning du.
Diffstat (limited to 'MobileCydia.mm')
-rw-r--r-- | MobileCydia.mm | 40 |
1 files changed, 6 insertions, 34 deletions
diff --git a/MobileCydia.mm b/MobileCydia.mm index 1968599..ca91d08 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -4728,41 +4728,13 @@ static _H<NSMutableSet> Diversions_; nil]; } -- (NSNumber *) du:(NSString *)path { - NSNumber *value(nil); - - int fds[2]; - _assert(pipe(fds) != -1); - - pid_t pid(ExecFork()); - if (pid == 0) { - _assert(dup2(fds[1], 1) != -1); - _assert(close(fds[0]) != -1); - _assert(close(fds[1]) != -1); - /* XXX: this should probably not use du */ - _root(execl("/usr/libexec/cydia/du", "du", "-s", [path UTF8String], NULL)); - exit(1); - } else { - _assert(close(fds[1]) != -1); +ssize_t DiskUsage(const char *path); - if (FILE *du = fdopen(fds[0], "r")) { - char line[1024]; - while (fgets(line, sizeof(line), du) != NULL) { - size_t length(strlen(line)); - while (length != 0 && line[length - 1] == '\n') - line[--length] = '\0'; - if (char *tab = strchr(line, '\t')) { - *tab = '\0'; - value = [NSNumber numberWithUnsignedLong:strtoul(line, NULL, 0)]; - } - } - - fclose(du); - } else - _assert(close(fds[0]) != -1); - } ReapZombie(pid); - - return value; +- (NSNumber *) du:(NSString *)path { + ssize_t usage(DiskUsage([path UTF8String])); + if (usage != -1) + usage /= 1024; + return [NSNumber numberWithUnsignedLong:usage]; } - (void) close { |