const char kExternalStoragePrivilege[] =
"http://tizen.org/privilege/externalstorage.appdata";
const char kSystemShareGroupName[] = "system_share";
-
+const char kSubssesionDir[] = "subsession";
// the input path should be root directory of package.
// for example: "../apps_rw/pkgid" or "../.shared/pkgid"
bool SetPackageDirectoryOwnerAndPermissions(const bf::path& path, uid_t uid) {
return false;
std::vector<std::string> shared_dirs(kSharedDataEntries);
- for (auto entry : shared_dirs) {
+ for (const auto& entry : shared_dirs) {
if (!ci::RemoveAll(path / entry / pkgid))
return false;
}
bool CreateSharedDataDirectories(const bf::path& path,
const std::string& pkgid) {
if (!ci::CreateDir(path / kSharedDir / pkgid / kData) ||
- !ci::CreateDir(path / kSharedTmpDir / pkgid))
+ !ci::CreateDir(path / kSharedTmpDir / pkgid) ||
+ !ci::CreateDir(path / pkgid / kShared))
return false;
bf::current_path(path / pkgid / kShared);
if (CreateExternalUserDirectories(user, pkgid, storage_apps_path.string()))
return false;
+ for (auto& lw_user : GetLightUserList(user)) {
+ bf::path storage_apps_lw_path = storage_apps_path
+ / kSubssesionDir / lw_user / "apps";
+ if (!bf::exists(storage_apps_lw_path)) {
+ bs::error_code error;
+ bf::create_directories(storage_apps_lw_path, error);
+ if (error) {
+ LOG(ERROR) << "Failed to create directory: "
+ << storage_apps_lw_path.c_str();
+ return false;
+ }
+ }
+
+ if (CreateExternalUserDirectories(user, pkgid,
+ storage_apps_lw_path.string()))
+ return false;
+ }
+
return true;
}
}
bf::path storage_apps_path = bf::path(storage_path) / "apps";
- return DeleteDirectories(
- GetDirectoryPathForStorage(user, storage_apps_path.string()), pkgid);
+ if (!DeleteDirectories(
+ GetDirectoryPathForStorage(user, storage_apps_path.string()), pkgid))
+ return false;
+
+ for (auto& lw_user : GetLightUserList(user)) {
+ bf::path storage_apps_lw_path =
+ storage_apps_path / kSubssesionDir / lw_user / "apps";
+ if (!DeleteDirectories(
+ GetDirectoryPathForStorage(user, storage_apps_lw_path.string()),
+ pkgid))
+ return false;
+ }
+
+ return true;
}
bool PerformExternalDirectoryCreationForAllUsers(const std::string& pkgid) {
UserList list = ci::GetUserList();
- for (auto l : list) {
+ for (const auto& l : list) {
if (!PerformExternalDirectoryCreationForUser(std::get<0>(l),
pkgid))
LOG(WARNING) << "Could not create external storage directories for user: "
bool PerformExternalDirectoryCreationForAllPkgs() {
UserList list = ci::GetUserList();
- for (auto l : list) {
+ for (const auto& l : list) {
uid_t uid = std::get<0>(l);
pkgmgrinfo_pkginfo_filter_h filter_handle = nullptr;
int ret = pkgmgrinfo_pkginfo_filter_create(&filter_handle);
ret = pkgmgrinfo_pkginfo_filter_foreach_pkginfo(filter_handle,
[](const pkgmgrinfo_pkginfo_h handle, void* user_data) -> int {
- uid_t uid =
+ uid_t u =
static_cast<uid_t>(reinterpret_cast<uintptr_t>(user_data));
char* pkgid = nullptr;
- int ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
- if (ret != PMINFO_R_OK)
+ int r = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
+ if (r != PMINFO_R_OK)
return -1;
- if (!PerformExternalDirectoryCreationForUser(uid, pkgid))
+ if (!PerformExternalDirectoryCreationForUser(u, pkgid))
return -1;
return 0;
bool PerformExternalDirectoryDeletionForAllUsers(const std::string& pkgid) {
UserList list = ci::GetUserList();
- for (auto l : list) {
+ for (const auto& l : list) {
uid_t uid = std::get<0>(l);
ci::PkgQueryInterface pkg_query(pkgid, uid);
LOG(DEBUG) << "Deleting directories for user: " << uid;
}
std::string error_message;
- if (!RegisterSecurityContextForPath(pkgid, skel_apps_rw / pkgid,
- kGlobalUserUid, is_readonly, &error_message)) {
+ if (!RegisterSecurityContextForPath(pkgid, {}, skel_apps_rw / pkgid,
+ kGlobalUserUid, is_readonly, &error_message)) {
LOG(ERROR) << "Failed to register security context for path: "
<< skel_apps_rw / pkgid << ", error_message: " << error_message;
return false;
}
+ if (!is_readonly) {
+ bf::path src_dir = bf::path(tzplatform_getenv(TZ_SYS_RW_APP)) / pkgid;
+ if (!CreateSymlinkFiles(src_dir, skel_apps_rw / pkgid))
+ return false;
+ }
+
// create per user dir
UserList list = ci::GetUserList();
- for (auto l : list) {
+ for (const auto& l : list) {
uid_t uid = std::get<0>(l);
- bf::path apps_rw = std::get<2>(l) / "apps_rw";
+ bf::path owner_apps_rw = std::get<2>(l) / "apps_rw";
+ std::vector<bf::path> apps_rw_paths;
+ apps_rw_paths.push_back(std::move(owner_apps_rw));
+
+ for (auto& lw_user : GetLightUserList(uid))
+ apps_rw_paths.push_back(std::get<2>(l)
+ / kSubssesionDir / lw_user / "apps_rw");
+
LOG(DEBUG) << "Creating directories for user: " << uid;
- if (!::CreateStorageDirectories(apps_rw, pkgid, trusted, shareddata,
- additional_dirs)) {
- LOG(ERROR) << "Failed to create storage directory for user: " << uid;
- return false;
- }
+ for (auto& apps_rw : apps_rw_paths) {
+ if (!::CreateStorageDirectories(apps_rw, pkgid, trusted, shareddata,
+ additional_dirs)) {
+ LOG(ERROR) << "Failed to create storage directory for user: " << uid;
+ return false;
+ }
- if (!::SetPackageDirectoryOwnerAndPermissions(apps_rw / pkgid, uid))
- return false;
+ if (!::SetPackageDirectoryOwnerAndPermissions(apps_rw / pkgid, uid))
+ return false;
- if (shareddata) {
- std::vector<std::string> shared_dirs(kSharedDataEntries);
- for (auto entry : shared_dirs) {
- bf::path shared_dst = apps_rw / entry / pkgid;
- if (!::SetPackageDirectoryOwnerAndPermissions(shared_dst, uid))
- return false;
+ if (shareddata) {
+ std::vector<std::string> shared_dirs(kSharedDataEntries);
+ for (const auto& entry : shared_dirs) {
+ bf::path shared_dst = apps_rw / entry / pkgid;
+ if (!::SetPackageDirectoryOwnerAndPermissions(shared_dst, uid))
+ return false;
+ }
}
- }
- if (!RegisterSecurityContextForPath(pkgid, apps_rw / pkgid, uid,
- false, &error_message)) {
- LOG(ERROR) << "Failed to register security context for path: "
- << apps_rw / pkgid << ", error_message: " << error_message;
- return false;
+ if (!RegisterSecurityContextForPath(pkgid, {}, apps_rw / pkgid, uid,
+ false, &error_message)) {
+ LOG(ERROR) << "Failed to register security context for path: "
+ << apps_rw / pkgid << ", error_message: " << error_message;
+ return false;
+ }
}
}
return true;
}
-bool DeletePerUserStorageDirectories(const std::string& pkgid) {
+bool DeletePerUserStorageDirectories(const std::string& pkgid,
+ bool keep_rwdata) {
// delete skel dir
bf::path skel_apps_rw = bf::path(tzplatform_getenv(TZ_SYS_ETC)) /
bf::path(kSkelAppDir);
return false;
}
+ if (keep_rwdata)
+ return true;
+
// delete per user dir
UserList list = ci::GetUserList();
- for (auto l : list) {
+ for (const auto& l : list) {
uid_t uid = std::get<0>(l);
- bf::path apps_rw = std::get<2>(l) / "apps_rw";
+ bf::path owner_apps_rw = std::get<2>(l) / "apps_rw";
+ std::vector<bf::path> apps_rw_paths;
+ apps_rw_paths.push_back(std::move(owner_apps_rw));
+
+ for (auto& lw_user : GetLightUserList(uid))
+ apps_rw_paths.push_back(std::get<2>(l) / kSubssesionDir / lw_user /
+ "apps_rw");
+
LOG(DEBUG) << "Deleting directories for user: " << uid;
- if (!ci::RemoveAll(apps_rw / pkgid)) {
- LOG(ERROR) << "Failed to delete storage directory for user: " << uid;
- return false;
+ for (auto& apps_rw : apps_rw_paths) {
+ if (!ci::RemoveAll(apps_rw / pkgid)) {
+ LOG(ERROR) << "Failed to delete storage directory for user: " << uid;
+ return false;
+ }
}
+ }
- if (!ci::DeletePerUserSharedDataDir(pkgid)) {
- LOG(ERROR) << "Failed to delete per user shared data dir";
- return false;
- }
+ if (!ci::DeletePerUserSharedDataDir(pkgid)) {
+ LOG(ERROR) << "Failed to delete per user shared data dir";
+ return false;
}
return true;
if (!::SetPackageDirectoryOwnerAndPermissions(path / pkgid, uid))
return false;
+ if (shareddata) {
+ std::vector<std::string> shared_dirs(kSharedDataEntries);
+ for (const auto& entry : shared_dirs) {
+ bf::path shared_dst = path / entry / pkgid;
+ if (!::SetPackageDirectoryOwnerAndPermissions(shared_dst, uid))
+ return false;
+ }
+ }
+
std::string error_message;
- if (!RegisterSecurityContextForPath(pkgid, path / pkgid, uid, false,
- &error_message)) {
+ if (!RegisterSecurityContextForPath(pkgid, {}, path / pkgid, uid, false,
+ &error_message)) {
LOG(ERROR) << "Failed to register security context for path: " << path
<< ", error_message: " << error_message;
return false;
return true;
}
-bool DeleteStorageDirectories(const boost::filesystem::path& path,
- const std::string& pkgid) {
- std::vector<const char*> dirs;
- dirs.assign(kEntries.begin() + 1, kEntries.end());
- dirs.push_back(kSharedTrustedDir);
- dirs.push_back(kSharedCacheDir);
- for (auto& entry : dirs) {
- bf::path subpath = path / pkgid / entry;
- if (!ci::RemoveAll(subpath))
- return false;
- }
- if (!DeleteSharedDataDirectories(path, pkgid))
- return false;
-
- return true;
+void RemoveRWDirectories(const boost::filesystem::path& root) {
+ if (!RemoveAll(root / kCache))
+ LOG(ERROR) << "Failed to remove packaged cache directory";
+ if (!RemoveAll(root / kData))
+ LOG(ERROR) << "Failed to remove packaged data directory";
+ if (!RemoveAll(root / kSharedCacheDir))
+ LOG(ERROR) << "Failed to remove packaged shared/cache directory";
+ if (!RemoveAll(root / kSharedDataDir))
+ LOG(ERROR) << "Failed to remove packaged shared/data directory";
+ if (!RemoveAll(root / kSharedTrustedDir))
+ LOG(ERROR) << "Failed to remove packaged shared/trusted directory";
}
bool DeleteSharedDirectories(const bf::path& path,
bool DeleteUserExternalDirectories(const std::string& pkgid) {
UserList list = ci::GetUserList();
- for (auto l : list) {
+ for (const auto& l : list) {
uid_t uid = std::get<0>(l);
ci::PkgQueryInterface pkg_query(pkgid, uid);
if (pkg_query.IsPackageInstalled()) {
if (!DeleteDirectories(apps_rw, pkgid)) {
return false;
}
+
+ for (auto& lw_user : GetLightUserList(uid)) {
+ bf::path apps_rw_lw(std::get<2>(l) / kSubssesionDir / lw_user / "apps_rw");
+ if (!DeleteDirectories(apps_rw_lw, pkgid))
+ return false;
+ }
}
+
return true;
}
return false;
}
- bool result = true;
UserList list = ci::GetUserList();
- for (auto l : list) {
+ for (const auto& l : list) {
uid_t uid = std::get<0>(l);
LOG(DEBUG) << "Creating symlinks for uid: " << uid;
// check installed user private app.
ci::PkgQueryInterface pkg_query(pkgid, uid);
if (pkg_query.IsPackageInstalled())
continue;
- bf::path apps_rw(std::get<2>(l) / "apps_rw");
- bf::path dst_dir = apps_rw / pkgid;
- if (!bf::exists(dst_dir)) {
- LOG(WARNING) << "dst_dir not exists";
- continue;
+
+ bf::path owner_apps_rw = std::get<2>(l) / "apps_rw";
+ std::vector<bf::path> apps_rw_paths;
+ apps_rw_paths.push_back(std::move(owner_apps_rw));
+
+ for (auto& lw_user : GetLightUserList(uid))
+ apps_rw_paths.push_back(std::get<2>(l) / kSubssesionDir / lw_user /
+ "apps_rw");
+
+ for (auto& apps_rw : apps_rw_paths) {
+ bf::path dst_dir = apps_rw / pkgid;
+ if (!bf::exists(dst_dir)) {
+ LOG(WARNING) << "dst_dir not exists";
+ continue;
+ }
+
+ if (!CreateSymlinkFiles(src_dir, dst_dir))
+ return false;
}
- result = CreateSymlinkFiles(src_dir, dst_dir);
}
- return result;
+
+ return true;
}
bool CreateGlobalAppSymlinksForUser(const std::string& pkgid, uid_t uid) {
return true;
}
- bool result = true;
UserList list = ci::GetUserList();
- for (auto l : list) {
+ for (const auto& l : list) {
uid_t uid = std::get<0>(l);
LOG(DEBUG) << "Deleting symlinks for uid: " << uid;
+
// check installed user private app.
ci::PkgQueryInterface pkg_query(pkgid, uid);
if (pkg_query.IsPackageInstalled())
continue;
- bf::path apps_rw(std::get<2>(l) / "apps_rw");
- bf::path dst_dir = apps_rw / pkgid;
- if (!bf::exists(dst_dir)) {
- LOG(WARNING) << "dst_dir not exists";
- continue;
+
+ bf::path owner_apps_rw = std::get<2>(l) / "apps_rw";
+ std::vector<bf::path> apps_rw_paths;
+ apps_rw_paths.push_back(std::move(owner_apps_rw));
+ for (auto& lw_user : GetLightUserList(uid))
+ apps_rw_paths.push_back(std::get<2>(l) / kSubssesionDir / lw_user /
+ "apps_rw");
+
+ for (auto& apps_rw : apps_rw_paths) {
+ bf::path dst_dir = apps_rw / pkgid;
+ if (!bf::exists(dst_dir)) {
+ LOG(WARNING) << "dst_dir not exists";
+ continue;
+ }
+
+ if (!DeleteSymlinkFiles(src_dir, dst_dir))
+ return false;
}
- result = DeleteSymlinkFiles(src_dir, dst_dir);
}
- return result;
+
+ return true;
}
bool DeleteGlobalAppSymlinksForUser(const std::string& pkgid, uid_t uid) {
bf::path path = apps_rw / pkgid;
std::string error_message;
- if (!ci::RegisterSecurityContextForPath(pkgid, path, uid, false,
- &error_message)) {
+ if (!ci::RegisterSecurityContextForPath(pkgid, {}, path, uid, false,
+ &error_message)) {
LOG(ERROR) << "Failed to register security context for path: " << path
<< ", error_message: " << error_message;
return false;
return false;
std::string error_message;
- if (!ci::RegisterSecurityContextForPath(pkgid, skel_apps_rw / pkgid,
- kGlobalUserUid, false, &error_message)) {
+ if (!ci::RegisterSecurityContextForPath(pkgid, {}, skel_apps_rw / pkgid,
+ kGlobalUserUid, false, &error_message)) {
LOG(ERROR) << "Failed to register security context for path: "
<< skel_apps_rw / pkgid << ", error_message: " << error_message;
return false;
// create per user dir
ci::UserList list = ci::GetUserList();
- for (auto l : list) {
+ for (const auto& l : list) {
uid_t uid = std::get<0>(l);
LOG(DEBUG) << "Adding shareddata directory for uid: " << uid;
- bf::path apps_rw = ci::GetRootAppPath(false, uid);
- if (!CreateSharedDataDirectories(apps_rw, pkgid))
- return false;
+ bf::path owner_apps_rw = ci::GetRootAppPath(false, uid);
+ std::vector<bf::path> apps_rw_paths;
+ apps_rw_paths.push_back(std::move(owner_apps_rw));
+ for (auto& lw_user : GetLightUserList(uid))
+ apps_rw_paths.push_back(std::get<2>(l) / kSubssesionDir / lw_user /
+ "apps_rw");
- std::vector<std::string> shared_dirs(kSharedDataEntries);
- for (auto entry : shared_dirs) {
- bf::path shared_dst = apps_rw / entry / pkgid;
- if (!::SetPackageDirectoryOwnerAndPermissions(shared_dst, uid))
+ for (auto& apps_rw : apps_rw_paths) {
+ if (!CreateSharedDataDirectories(apps_rw, pkgid))
return false;
- }
- std::string error_message;
- if (!ci::RegisterSecurityContextForPath(pkgid, apps_rw / pkgid, uid,
- false, &error_message)) {
- LOG(ERROR) << "Failed to register security context for path: "
- << apps_rw / pkgid << ", error_message: " << error_message;
- return false;
+ std::vector<std::string> shared_dirs(kSharedDataEntries);
+ for (const auto& entry : shared_dirs) {
+ bf::path shared_dst = apps_rw / entry / pkgid;
+ if (!::SetPackageDirectoryOwnerAndPermissions(shared_dst, uid))
+ return false;
+ }
+
+ if (!ci::RegisterSecurityContextForPath(pkgid, {}, apps_rw / pkgid, uid,
+ false, &error_message)) {
+ LOG(ERROR) << "Failed to register security context for path: "
+ << apps_rw / pkgid << ", error_message: " << error_message;
+ return false;
+ }
}
}
return false;
ci::UserList list = ci::GetUserList();
- for (auto l : list) {
+ for (const auto& l : list) {
uid_t uid = std::get<0>(l);
- bf::path apps_rw = ci::GetRootAppPath(false, uid);
- if (!DeleteSharedDataDirectories(apps_rw, pkgid))
- return false;
- }
+ bf::path owner_apps_rw = ci::GetRootAppPath(false, uid);
+ std::vector<bf::path> apps_rw_paths;
+ apps_rw_paths.push_back(std::move(owner_apps_rw));
+ for (auto& lw_user : GetLightUserList(uid))
+ apps_rw_paths.push_back(std::get<2>(l) / kSubssesionDir / lw_user /
+ "apps_rw");
+
+ for (auto& apps_rw : apps_rw_paths) {
+ if (!DeleteSharedDataDirectories(apps_rw, pkgid))
+ return false;
+ }
+ }
return true;
}
return false;
ci::UserList list = ci::GetUserList();
- for (auto l : list) {
+ for (const auto& l : list) {
uid_t uid = std::get<0>(l);
- if (!BackupSharedDataDir(pkgid, uid))
- return false;
+ bf::path owner_apps_rw = ci::GetRootAppPath(false, uid);
+ std::vector<bf::path> apps_rw_paths;
+ apps_rw_paths.push_back(std::move(owner_apps_rw));
+ for (auto& lw_user : GetLightUserList(uid))
+ apps_rw_paths.push_back(std::get<2>(l) / kSubssesionDir / lw_user /
+ "apps_rw");
+
+ for (auto& apps_rw : apps_rw_paths) {
+ if (!BackupSharedDataDirectories(apps_rw, pkgid))
+ return false;
+ }
}
return true;
bool RestoreSharedDataDir(const std::string& pkgid, uid_t uid) {
bf::path apps_rw = ci::GetRootAppPath(false, uid);
- return RestoreSharedDataDirectories(apps_rw, pkgid);
+ if (!RestoreSharedDataDirectories(apps_rw, pkgid))
+ return false;
+
+ if (!::SetPackageDirectoryOwnerAndPermissions(apps_rw / pkgid, uid))
+ return false;
+
+ std::vector<std::string> shared_dirs(kSharedDataEntries);
+ for (const auto& entry : shared_dirs) {
+ bf::path shared_dst = apps_rw / entry / pkgid;
+ if (!::SetPackageDirectoryOwnerAndPermissions(shared_dst, uid))
+ return false;
+ }
+
+ std::string error_message;
+ if (!RegisterSecurityContextForPath(pkgid, {}, apps_rw / pkgid, uid, false,
+ &error_message)) {
+ LOG(ERROR) << "Failed to register security context for path: " << apps_rw
+ << ", error_message: " << error_message;
+ return false;
+ }
+
+ return true;
}
bool RestorePerUserSharedDataDir(const std::string& pkgid) {
if (!RestoreSharedDataDirectories(skel_apps_rw, pkgid))
return false;
+ std::string error_message;
ci::UserList list = ci::GetUserList();
- for (auto l : list) {
+ for (const auto& l : list) {
uid_t uid = std::get<0>(l);
- if (!RestoreSharedDataDir(pkgid, uid))
- return false;
+ bf::path owner_apps_rw = ci::GetRootAppPath(false, uid);
+ std::vector<bf::path> apps_rw_paths;
+ apps_rw_paths.push_back(std::move(owner_apps_rw));
+ for (auto& lw_user : GetLightUserList(uid))
+ apps_rw_paths.push_back(std::get<2>(l) / kSubssesionDir / lw_user /
+ "apps_rw");
+
+ for (auto& apps_rw : apps_rw_paths) {
+ if (!RestoreSharedDataDirectories(apps_rw, pkgid))
+ return false;
+
+ if (!::SetPackageDirectoryOwnerAndPermissions(apps_rw / pkgid, uid))
+ return false;
+
+ std::vector<std::string> shared_dirs(kSharedDataEntries);
+ for (const auto& entry : shared_dirs) {
+ bf::path shared_dst = apps_rw / entry / pkgid;
+ if (!::SetPackageDirectoryOwnerAndPermissions(shared_dst, uid))
+ return false;
+ }
+
+ if (!RegisterSecurityContextForPath(pkgid, {}, apps_rw / pkgid, uid,
+ false, &error_message)) {
+ LOG(ERROR) << "Failed to register security context for path: "
+ << apps_rw / pkgid << ", error_message: " << error_message;
+ return false;
+ }
+ }
}
return true;
return false;
ci::UserList list = ci::GetUserList();
- for (auto l : list) {
+ for (const auto& l : list) {
uid_t uid = std::get<0>(l);
- if (!RemoveBackupSharedDataDir(pkgid, uid))
- return false;
+ bf::path owner_apps_rw = ci::GetRootAppPath(false, uid);
+ std::vector<bf::path> apps_rw_paths;
+ apps_rw_paths.push_back(std::move(owner_apps_rw));
+ for (auto& lw_user : GetLightUserList(uid))
+ apps_rw_paths.push_back(std::get<2>(l) / kSubssesionDir / lw_user /
+ "apps_rw");
+
+ for (auto& apps_rw : apps_rw_paths) {
+ if (!RemoveBackupSharedDataDirectories(apps_rw, pkgid))
+ return false;
+ }
}
return true;