2022-05-18 01:55:58 -07:00
|
|
|
#include <base.hpp>
|
2023-11-08 01:46:02 -08:00
|
|
|
#include <consts.hpp>
|
|
|
|
#include <core.hpp>
|
2025-01-03 11:38:15 -08:00
|
|
|
#include <sqlite.hpp>
|
2022-05-20 04:37:37 -07:00
|
|
|
#include <flags.h>
|
2022-05-18 01:55:58 -07:00
|
|
|
|
|
|
|
using namespace std;
|
2023-06-14 22:24:42 +08:00
|
|
|
|
2022-05-18 01:55:58 -07:00
|
|
|
// app_id = app_no + AID_APP_START
|
|
|
|
// app_no range: [0, 9999]
|
|
|
|
vector<bool> get_app_no_list() {
|
|
|
|
vector<bool> list;
|
|
|
|
auto data_dir = xopen_dir(APP_DATA_DIR);
|
|
|
|
if (!data_dir)
|
|
|
|
return list;
|
|
|
|
dirent *entry;
|
|
|
|
while ((entry = xreaddir(data_dir.get()))) {
|
|
|
|
// For each user
|
|
|
|
int dfd = xopenat(dirfd(data_dir.get()), entry->d_name, O_RDONLY);
|
|
|
|
if (auto dir = xopen_dir(dfd)) {
|
|
|
|
while ((entry = xreaddir(dir.get()))) {
|
|
|
|
// For each package
|
|
|
|
struct stat st{};
|
|
|
|
xfstatat(dfd, entry->d_name, &st, 0);
|
|
|
|
int app_id = to_app_id(st.st_uid);
|
|
|
|
if (app_id >= AID_APP_START && app_id <= AID_APP_END) {
|
|
|
|
int app_no = app_id - AID_APP_START;
|
|
|
|
if (list.size() <= app_no) {
|
|
|
|
list.resize(app_no + 1);
|
|
|
|
}
|
|
|
|
list[app_no] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
close(dfd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|