Skip to content

Commit f41496f

Browse files
author
Dianne Hackborn
committed
Fix issue #7202950: After clearing data, clear data button is still enabled.
Count the lib symlink against the app's code size. Also be sure to look at the new separate lib path for apps, and tweak the size counting to also count the size of directory entries. Change-Id: I4b0fd5771f249faa05fd72f08062df885902cc97
1 parent 580ee8b commit f41496f

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

cmds/installd/commands.c

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,16 @@ int get_size(const char *pkgname, int persona, const char *apkpath,
447447
}
448448
}
449449

450+
/* add in size of any libraries */
451+
if (!create_pkg_path_in_dir(path, &android_app_lib_dir, pkgname, PKG_DIR_POSTFIX)) {
452+
d = opendir(path);
453+
if (d != NULL) {
454+
dfd = dirfd(d);
455+
codesize += calculate_dir_size(dfd);
456+
closedir(d);
457+
}
458+
}
459+
450460
/* compute asec size if it is given
451461
*/
452462
if (asecpath != NULL && asecpath[0] != '!') {
@@ -474,21 +484,33 @@ int get_size(const char *pkgname, int persona, const char *apkpath,
474484

475485
if (de->d_type == DT_DIR) {
476486
int subfd;
487+
int64_t statsize = 0;
488+
int64_t dirsize = 0;
477489
/* always skip "." and ".." */
478490
if (name[0] == '.') {
479491
if (name[1] == 0) continue;
480492
if ((name[1] == '.') && (name[2] == 0)) continue;
481493
}
494+
if (fstatat(dfd, name, &s, AT_SYMLINK_NOFOLLOW) == 0) {
495+
statsize = stat_size(&s);
496+
}
482497
subfd = openat(dfd, name, O_RDONLY | O_DIRECTORY);
483498
if (subfd >= 0) {
484-
int64_t size = calculate_dir_size(subfd);
485-
if (!strcmp(name,"lib")) {
486-
codesize += size;
487-
} else if(!strcmp(name,"cache")) {
488-
cachesize += size;
489-
} else {
490-
datasize += size;
491-
}
499+
dirsize = calculate_dir_size(subfd);
500+
}
501+
if(!strcmp(name,"lib")) {
502+
codesize += dirsize + statsize;
503+
} else if(!strcmp(name,"cache")) {
504+
cachesize += dirsize + statsize;
505+
} else {
506+
datasize += dirsize + statsize;
507+
}
508+
} else if (de->d_type == DT_LNK && !strcmp(name,"lib")) {
509+
// This is the symbolic link to the application's library
510+
// code. We'll count this as code instead of data, since
511+
// it is not something that the app creates.
512+
if (fstatat(dfd, name, &s, AT_SYMLINK_NOFOLLOW) == 0) {
513+
codesize += stat_size(&s);
492514
}
493515
} else {
494516
if (fstatat(dfd, name, &s, AT_SYMLINK_NOFOLLOW) == 0) {

libs/diskusage/dirsize.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ int64_t calculate_dir_size(int dfd)
4949

5050
while ((de = readdir(d))) {
5151
const char *name = de->d_name;
52+
if (fstatat(dfd, name, &s, AT_SYMLINK_NOFOLLOW) == 0) {
53+
size += stat_size(&s);
54+
}
5255
if (de->d_type == DT_DIR) {
5356
int subfd;
5457

@@ -64,10 +67,6 @@ int64_t calculate_dir_size(int dfd)
6467
if (subfd >= 0) {
6568
size += calculate_dir_size(subfd);
6669
}
67-
} else {
68-
if (fstatat(dfd, name, &s, AT_SYMLINK_NOFOLLOW) == 0) {
69-
size += stat_size(&s);
70-
}
7170
}
7271
}
7372
closedir(d);

0 commit comments

Comments
 (0)