summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Freeman (saurik) <saurik@saurik.com>2015-07-05 00:53:52 -0700
committerJay Freeman (saurik) <saurik@saurik.com>2015-07-05 00:53:52 -0700
commitd59938e3a2131e61f875f6eff48af5f89f57c732 (patch)
tree38e2ef71289b0ff7c27ffe86fa6cc51de4726234
parent9adfb865fde8fc0e7b93962e57e3922a66fd180d (diff)
Just go ahead and use du (since we have it still).
-rw-r--r--MobileCydia.mm24
1 files changed, 18 insertions, 6 deletions
diff --git a/MobileCydia.mm b/MobileCydia.mm
index 1127bb0..5596759 100644
--- a/MobileCydia.mm
+++ b/MobileCydia.mm
@@ -4722,13 +4722,25 @@ static _H<NSMutableSet> Diversions_;
nil];
}
-ssize_t DiskUsage(const char *path);
-
- (NSNumber *) du:(NSString *)path {
- ssize_t usage(DiskUsage([path UTF8String]));
- if (usage != -1)
- usage /= 1024;
- return [NSNumber numberWithUnsignedLong:usage];
+ NSNumber *value(nil);
+
+ FILE *du(popen([[NSString stringWithFormat:@"/usr/libexec/cydia/cydo /usr/libexec/cydia/du -ks %@", path] UTF8String], "r"));
+ if (du != NULL) {
+ 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)];
+ }
+ }
+ pclose(du);
+ }
+
+ return value;
}
- (void) close {