}
bool CreateStorageDirectories(const boost::filesystem::path& path,
- const std::string& api_version,
bool trusted, bool shareddata,
const std::vector<const char*> additional_dirs) {
if (!bf::exists(path)) {
}
}
- utils::VersionNumber api_ver(api_version);
std::vector<const char*> dirs(kEntries);
dirs.insert(dirs.end(), additional_dirs.begin(), additional_dirs.end());
if (trusted)
dirs.push_back(kSharedTrustedDir);
- if (api_ver < ver30 || shareddata) {
+ if (shareddata) {
dirs.push_back(kSharedDataDir);
} else {
bf::path shared_data_path = path / kSharedDataDir;
bool CreateStorageDirectories(const boost::filesystem::path& path,
const std::string& pkgid, uid_t uid,
- const std::string& api_version,
bool trusted, bool shareddata) {
- if (!::CreateStorageDirectories(path, api_version, trusted, shareddata,
+ if (!::CreateStorageDirectories(path, trusted, shareddata,
std::vector<const char*>())) {
LOG(ERROR) << "Failed to create storage directory for path: " << path;
return false;
}
bool CreateSkelDirectories(const std::string& pkgid,
- const std::string& api_version,
bool trusted, bool shareddata, bool is_readonly,
const std::vector<const char*> additional_dirs) {
bf::path path = bf::path(tzplatform_getenv(TZ_SYS_ETC)) /
bf::path(kSkelAppDir) / pkgid;
LOG(DEBUG) << "Creating directories in: " << path;
- if (!::CreateStorageDirectories(path, api_version, trusted, shareddata,
+ if (!::CreateStorageDirectories(path, trusted, shareddata,
additional_dirs)) {
LOG(ERROR) << "Failed to create storage directory for path: " << path;
return false;
return true;
}
+bool ShouldSupportLegacySharedDataDir(const std::string& api_version) {
+ utils::VersionNumber api_ver(api_version);
+ if (api_ver < ver30)
+ return true;
+ else
+ return false;
+}
+
} // namespace common_installer
* \param path base path, where storage directories will be created in
* \param pkgid package id
* \param uid user id
- * \param api_version package api version
* \param trusted signed package flag
* \param shareddata shared data privilege flag
*
*/
bool CreateStorageDirectories(const boost::filesystem::path& path,
const std::string& pkgid, uid_t uid,
- const std::string& api_version,
bool trusted, bool shareddata);
/**
* \brief Create skeleton directories for package
*
* \param pkgid package id
- * \param api_version package api version
* \param trusted signed package flag
* \param shareddata shared data privilege flag
* \param is_readonly readonly flag
*
*/
bool CreateSkelDirectories(const std::string& pkgid,
- const std::string& api_version,
bool trusted, bool shareddata, bool is_readonly,
const std::vector<const char*>
additional_dirs = std::vector<const char*>());
bool SetPackageDirectoryOwnerAndPermissions(const boost::filesystem::path& path,
uid_t uid);
+/**
+ * \brief Return true when installer should support legacy shared data directory.
+ *
+ * \param api_version package api version
+ *
+ * \return true when should support legacy shared data directory, false otherwise
+ */
+bool ShouldSupportLegacySharedDataDir(const std::string& api_version);
+
} // namespace common_installer
#endif // COMMON_SHARED_DIRS_H_
#include "common/step/filesystem/step_create_storage_directories.h"
-#include <manifest_parser/utils/version_number.h>
#include <pkgmgrinfo_basic.h>
#include <boost/filesystem/operations.hpp>
namespace filesystem {
bool StepCreateStorageDirectories::CreatePerUserStorageDirs(
- manifest_x *manifest, bool trusted, bool shareddata) {
+ bool trusted, bool shareddata) {
LOG(INFO) << "Creating per-user directories for package: "
<< context_->pkgid.get();
bool is_readonly = context_->is_readonly_package.get();
if (!CreateSkelDirectories(context_->pkgid.get(),
- manifest->api_version, trusted, shareddata, is_readonly,
+ trusted, shareddata, is_readonly,
additional_shared_dirs_)) {
LOG(ERROR) << "Failed to create skel dirs";
return false;
}
bool StepCreateStorageDirectories::CreateStorageDirs(
- manifest_x* manifest, bool trusted, bool shareddata) {
+ bool trusted, bool shareddata) {
if (!CreateStorageDirectories(context_->GetPkgPath(),
context_->pkgid.get(), context_->uid.get(),
- manifest->api_version,
trusted, shareddata)) {
LOG(ERROR) << "Failed to create storage directories";
return false;
trusted = true;
manifest_x* manifest = context_->manifest_data.get();
- bool shareddata = false;
+ bool shareddata = ShouldSupportLegacySharedDataDir(manifest->api_version);
for (auto& priv : GListRange<privilege_x*>(manifest->privileges)) {
if (!strcmp(priv->value, privileges::kPrivForSharedData)) {
shareddata = true;
}
if (context_->request_mode.get() == RequestMode::GLOBAL) {
- if (!CreatePerUserStorageDirs(manifest, trusted, shareddata))
+ if (!CreatePerUserStorageDirs(trusted, shareddata))
return Status::APP_DIR_ERROR;
} else {
- if (!CreateStorageDirs(manifest, trusted, shareddata))
+ if (!CreateStorageDirs(trusted, shareddata))
return Status::APP_DIR_ERROR;
}
return Status::OK;
Status precheck() override { return Status::OK; }
private:
- bool CreatePerUserStorageDirs(manifest_x* manifest, bool trusted,
- bool shareddata);
- bool CreateStorageDirs(manifest_x* manifest, bool trusted, bool shareddata);
+ bool CreatePerUserStorageDirs(bool trusted, bool shareddata);
+ bool CreateStorageDirs(bool trusted, bool shareddata);
std::vector<const char*> additional_shared_dirs_;
#include "common/step/filesystem/step_update_storage_directories.h"
-#include <manifest_parser/utils/version_number.h>
-
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/system/error_code.hpp>
namespace bf = boost::filesystem;
namespace bs = boost::system;
+namespace ci = common_installer;
namespace {
const char kSharedData[] = "shared/data";
const char kSkelApp[] = "skel/apps_rw";
-const utils::VersionNumber ver30("3.0");
bool CreateSharedDir(bf::path shareddir_path) {
if (bf::exists(shareddir_path))
return true;
}
+bool ShouldCreateSharedDataDir(manifest_x* manifest) {
+ bool shareddata = ci::ShouldSupportLegacySharedDataDir(manifest->api_version);
+ for (auto& priv : GListRange<privilege_x*>(manifest->privileges)) {
+ if (!strcmp(priv->value, ci::privileges::kPrivForSharedData)) {
+ shareddata = true;
+ break;
+ }
+ }
+ return shareddata;
+}
+
} // namespace
namespace common_installer {
bool StepUpdateStorageDirectories::UpdatePerUserStorageDirectories() {
manifest_x* manifest = context_->manifest_data.get();
- std::string package_id = context_->pkgid.get();
- utils::VersionNumber api_version(manifest->api_version);
-
- if (api_version < ver30) {
- return CreatePerUserSharedDir(package_id);
- } else {
- bool shareddata = false;
- for (auto& priv : GListRange<privilege_x*>(manifest->privileges)) {
- if (!strcmp(priv->value, privileges::kPrivForSharedData)) {
- shareddata = true;
- break;
- }
- }
-
- if (shareddata)
- return CreatePerUserSharedDir(package_id);
- else
- return RemovePerUserSharedDir(package_id);
- }
- return true;
+ if (ShouldCreateSharedDataDir(manifest))
+ return CreatePerUserSharedDir(context_->pkgid.get());
+ else
+ return RemovePerUserSharedDir(context_->pkgid.get());
}
bool StepUpdateStorageDirectories::UpdateStorageDirectories() {
manifest_x* manifest = context_->manifest_data.get();
- std::string str_ver(manifest->api_version);
- utils::VersionNumber api_version(str_ver);
-
bf::path shared_data_path = context_->GetPkgPath() / kSharedData;
- if (api_version < ver30) {
+ if (ShouldCreateSharedDataDir(manifest)) {
return CreateSharedDir(shared_data_path);
} else {
- bool shareddata = false;
- for (auto& priv : GListRange<privilege_x*>(manifest->privileges)) {
- if (!strcmp(priv->value, privileges::kPrivForSharedData)) {
- shareddata = true;
- break;
- }
- }
- if (shareddata) {
- return CreateSharedDir(shared_data_path);
- } else {
- if (!RemoveAll(shared_data_path))
- return false;
- }
+ if (!RemoveAll(shared_data_path))
+ return false;
}
return true;
}