diff options
| author | 2015-04-10 21:00:41 +0000 | |
|---|---|---|
| committer | 2015-04-10 21:00:51 +0000 | |
| commit | dfc30ae393fd610fcbd05a1ecfe7d4834a792de3 (patch) | |
| tree | 1344453051c65a405a0ec2e2c3402ca3266bf9b7 /cmds/installd/utils.cpp | |
| parent | 44a38d9337989742046c1e3faa6e7392ecc47cd4 (diff) | |
| parent | e36372423000a906bafae68844ebc6c42d09335a (diff) | |
Merge "Command to move private app data between volumes."
Diffstat (limited to 'cmds/installd/utils.cpp')
| -rw-r--r-- | cmds/installd/utils.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/cmds/installd/utils.cpp b/cmds/installd/utils.cpp index e10116eb83..ba411cd478 100644 --- a/cmds/installd/utils.cpp +++ b/cmds/installd/utils.cpp @@ -99,6 +99,38 @@ std::string create_data_media_path(const char* volume_uuid, userid_t userid) { return StringPrintf("%s/media/%u", create_data_path(volume_uuid).c_str(), userid); } +std::vector<userid_t> get_known_users(const char* volume_uuid) { + std::vector<userid_t> users; + + // We always have an owner + users.push_back(0); + + std::string path(create_data_path(volume_uuid) + "/" + SECONDARY_USER_PREFIX); + DIR* dir = opendir(path.c_str()); + if (dir == NULL) { + // Unable to discover other users, but at least return owner + PLOG(ERROR) << "Failed to opendir " << path; + return users; + } + + struct dirent* ent; + while ((ent = readdir(dir))) { + if (ent->d_type != DT_DIR) { + continue; + } + + char* end; + userid_t user = strtol(ent->d_name, &end, 10); + if (*end == '\0' && user != 0) { + LOG(DEBUG) << "Found valid user " << user; + users.push_back(user); + } + } + closedir(dir); + + return users; +} + /** * Create the path name for config for a certain userid. * Returns 0 on success, and -1 on failure. |