#include "common/shared_dirs.h"
+#include <manifest_parser/utils/logging.h>
+#include <manifest_parser/utils/version_number.h>
+
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/program_options.hpp>
#include <glib.h>
#include <gio/gio.h>
-#include <manifest_parser/utils/logging.h>
#include <vcore/Certificate.h>
#include <pkgmgr-info.h>
#include <pwd.h>
namespace {
+const utils::VersionNumber ver30("3.0");
+
typedef std::vector<std::tuple<uid_t, gid_t, bf::path>> user_list;
const std::vector<const char*> kEntries = {
{"/"},
{"cache/"},
{"data/"},
{"shared/"},
- {"shared/cache/"},
};
+const char kSharedDataDir[] = "shared/data";
const char kTrustedDir[] = "shared/trusted";
const char kSkelAppDir[] = "/etc/skel/apps_rw";
const char kPackagePattern[] = R"(^[0-9a-zA-Z_-]+(\.?[0-9a-zA-Z_-]+)*$)";
return true;
}
-bool CreateSkelDirectories(const std::string& pkgid) {
+bool CreateSkelDirectories(const std::string& pkgid,
+ const std::string& api_version,
+ bool trusted) {
bf::path path = bf::path(kSkelAppDir) / pkgid;
LOG(DEBUG) << "Creating directories in: " << path;
+
+ utils::VersionNumber api_ver(api_version);
+
bs::error_code error;
bf::create_directories(path, error);
return false;
}
- for (auto& entry : kEntries) {
+ std::vector<const char*> dirs(kEntries);
+ if (trusted)
+ dirs.push_back(kTrustedDir);
+ if (api_ver < ver30) {
+ dirs.push_back(kSharedDataDir);
+ }
+ for (auto& entry : dirs) {
bf::path subpath = path / entry;
bf::create_directories(subpath, error);
if (error && !bf::exists(subpath)) {
// Use of this source code is governed by an apache 2.0 license that can be
// found in the LICENSE file.
+#include "common/step/filesystem/step_create_per_user_storage_directories.h"
+
#include <string>
#include <vector>
-#include "common/step/filesystem/step_create_per_user_storage_directories.h"
#include "common/privileges.h"
#include "common/pkgdir_tool_request.h"
std::string package_id = context_->pkgid.get();
LOG(INFO) << "Creating per-user directories for package: " << package_id;
- if (!common_installer::CreateSkelDirectories(package_id)) {
+ manifest_x* manifest = context_->manifest_data.get();
+ std::string str_ver(manifest->api_version);
+ std::string author_id = context_->certificate_info.get().author_id.get();
+ bool trusted = false;
+ if (!author_id.empty())
+ trusted = true;
+
+ if (!common_installer::CreateSkelDirectories(package_id,
+ str_ver, trusted)) {
LOG(ERROR) << "Failed to create skel dirs";
return Status::APP_DIR_ERROR;
}
#include "common/step/filesystem/step_create_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>
const char kCache[] = "cache";
const char kData[] = "data";
const char kShared[] = "shared";
-const char kSharedData[] = "data";
-const char kSharedTrusted[] = "trusted";
+const char kSharedCache[] = "shared/cache";
+const char kSharedData[] = "shared/data";
+const char kSharedTrusted[] = "shared/trusted";
+const utils::VersionNumber ver30("3.0");
} // namespace
namespace filesystem {
common_installer::Step::Status StepCreateStorageDirectories::process() {
- if (context_->request_mode.get() == RequestMode::GLOBAL)
+ if (context_->request_mode.get() == RequestMode::GLOBAL) {
+ // remove packaged RW diriectories
+ RemoveAll();
return Status::OK;
+ }
if (!ShareDir())
return Status::APP_DIR_ERROR;
if (!PrivateDir())
bool StepCreateStorageDirectories::SubShareDir() {
bs::error_code error_code;
- bf::path shared_path = context_->pkg_path.get() / kShared;
- bf::path shared_trusted_path = shared_path / kSharedTrusted;
+ bf::path shared_trusted_path = context_->pkg_path.get() / kSharedTrusted;
bf::create_directory(shared_trusted_path, error_code);
if (error_code) {
LOG(ERROR) << "Failed to create shared/trusted directory for package";
return false;
}
- bf::path shared_data_path = shared_path / kSharedData;
- bf::create_directory(shared_data_path, error_code);
- if (error_code) {
- LOG(ERROR) << "Failed to create shared/data directory for package";
+ manifest_x* manifest = context_->manifest_data.get();
+ if (!manifest) {
+ LOG(ERROR) << "Failed to get manifest info";
return false;
}
+ std::string str_ver(manifest->api_version);
+ utils::VersionNumber api_version(str_ver);
+
+ bf::path shared_data_path = context_->pkg_path.get() / kSharedData;
+ bf::path shared_cache_path = context_->pkg_path.get() / kSharedCache;
+
+ if (api_version >= ver30) {
+ // remove shared/data (deprecated)
+ bf::remove_all(shared_data_path, error_code);
+ if (error_code) {
+ LOG(ERROR) << "Can't remove dir:" << shared_data_path;
+ return false;
+ }
+ } else {
+ bf::create_directory(shared_data_path, error_code);
+ if (error_code) {
+ LOG(ERROR) << "Failed to create shared/data directory for package";
+ return false;
+ }
+ }
- bf::path shared_cache_path = shared_path / kCache;
- bf::create_directory(shared_cache_path, error_code);
+ // remove shared/cache (do not support)
+ bf::remove_all(shared_cache_path, error_code);
if (error_code) {
- LOG(ERROR) << "Failed to create shared/cache directory for package";
+ LOG(ERROR) << "Can't remove dir:" << shared_cache_path;
return false;
}
return true;
}
+void StepCreateStorageDirectories::RemoveAll() {
+ bs::error_code error_code;
+ bf::path data_path = context_->pkg_path.get() / kData;
+ bf::path cache_path = context_->pkg_path.get() / kCache;
+ bf::path shared_data_path = context_->pkg_path.get() / kSharedData;
+ bf::path shared_cache_path = context_->pkg_path.get() / kSharedCache;
+ bf::path shared_trusted_path = context_->pkg_path.get() / kSharedTrusted;
+
+ bf::remove_all(data_path, error_code);
+ bf::remove_all(cache_path, error_code);
+ bf::remove_all(shared_data_path, error_code);
+ bf::remove_all(shared_cache_path, error_code);
+ bf::remove_all(shared_trusted_path, error_code);
+}
+
} // namespace filesystem
} // namespace common_installer