#include <boost/filesystem/path.hpp>
#include <boost/system/error_code.hpp>
+#include <pkgmgrinfo_basic.h>
+
#include "common/paths.h"
+#include "common/privileges.h"
+#include "common/shared_dirs.h"
#include "common/utils/file_util.h"
+#include "common/utils/glist_range.h"
+#include "common/utils/user_util.h"
+
+namespace bf = boost::filesystem;
+namespace ci = common_installer;
namespace {
const char kDataLocation[] = "data";
const char kSharedResLocation[] = "shared";
-} // namespace
+bool ShouldCreateSharedDataDir(manifest_x* manifest) {
+ if (ci::ShouldSupportLegacySharedDataDir(manifest->api_version))
+ return true;
-namespace bf = boost::filesystem;
+ for (auto& priv : GListRange<privilege_x*>(manifest->privileges)) {
+ if (!strcmp(priv->value, ci::privileges::kPrivForSharedData))
+ return true;
+ }
+
+ return false;
+}
+
+} // namespace
namespace common_installer {
namespace filesystem {
}
Step::Status StepRecoverStorageDirectories::RecoveryUpdate() {
- if (context_->request_mode.get() == RequestMode::GLOBAL)
- return Status::OK;
if (!context_->GetPkgPath().empty()) {
bf::path backup_path = common_installer::GetBackupPathForPackagePath(
context_->GetPkgPath());
MoveAppStorage(context_->GetPkgPath(), backup_path, kDataLocation);
MoveAppStorage(context_->GetPkgPath(), backup_path, kSharedResLocation);
}
+
+ manifest_x* manifest = context_->manifest_data.get();
+ if (!manifest) {
+ LOG(WARNING) << "Cannot find manifest data. "
+ "Some directories may not be recovered.";
+ return Status::OK;
+ }
+
+ if (ShouldCreateSharedDataDir(manifest)) {
+ if (context_->request_mode.get() == RequestMode::GLOBAL) {
+ if (!ci::RestorePerUserSharedDataDir(context_->pkgid.get()))
+ return Status::APP_DIR_ERROR;
+ } else {
+ if (!ci::RestoreSharedDataDir(context_->pkgid.get(),
+ context_->uid.get()))
+ return Status::APP_DIR_ERROR;
+ }
+ } else {
+ if (context_->request_mode.get() == RequestMode::GLOBAL) {
+ if (!ci::DeletePerUserSharedDataDir(context_->pkgid.get()))
+ return Status::APP_DIR_ERROR;
+ } else {
+ if (!ci::DeleteSharedDataDir(context_->pkgid.get(),
+ context_->uid.get()))
+ return Status::APP_DIR_ERROR;
+ }
+ }
}
return Status::OK;
}