step/filesystem/step_disable_external_mount.cc
step/filesystem/step_enable_external_mount.cc
step/filesystem/step_move_installed_storage.cc
+ step/filesystem/step_recover_change_owner.cc
step/filesystem/step_recover_files.cc
step/filesystem/step_recover_icons.cc
step/filesystem/step_recover_manifest.cc
#include <tzplatform_config.h>
#include <storage-internal.h>
+#include <vector>
+
#include "common/utils/user_util.h"
namespace bf = boost::filesystem;
return pkg_path / "tep";
}
+boost::filesystem::path GetIconPath(const bf::path& base_path,
+ const std::string& pkgid,
+ const bf::path& icon_filename,
+ const bf::path& root_path) {
+ std::vector<bf::path> paths;
+ bf::path system_path = base_path / icon_filename;
+ bf::path small_system_path = base_path / "default" / "small" / icon_filename;
+ bf::path res_path = root_path / pkgid / "res" / "icons" / icon_filename;
+
+ paths.push_back(system_path);
+ paths.push_back(small_system_path);
+ paths.push_back(res_path);
+
+ for (auto& path : paths) {
+ if (bf::exists(path))
+ return path;
+ }
+
+ return {};
+}
+
} // namespace common_installer
boost::filesystem::path GetInternalTepPath(
const boost::filesystem::path& pkg_path);
+/**
+ * @brief GetIconPath
+ * Returns internal location for preinstalled global app icon
+ * @param base_path path of icon in application
+ * @param pkgid package id
+ * @param icon_filename filename of icon
+ * @param root_path root path of application
+ *
+ * @return full icon path
+ */
+boost::filesystem::path GetIconPath(const boost::filesystem::path& base_path,
+ const std::string& pkgid,
+ const boost::filesystem::path& icon_filename,
+ const boost::filesystem::path& root_path);
+
} // namespace common_installer
#endif // COMMON_PATHS_H_
#include <string>
#include <vector>
+#include "common/paths.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 bs = boost::system;
namespace ci = common_installer;
-namespace {
-
-bool SetOwner(const bf::path& subpath, uid_t uid, gid_t gid) {
- int fd = open(subpath.c_str(), O_RDONLY);
- if (fd < 0) {
- LOG(ERROR) << "Can't open directory : " << subpath;
- return false;
- }
-
- int ret = fchown(fd, uid, gid);
- close(fd);
- if (ret != 0) {
- LOG(ERROR) << "Failed to change owner of: " << subpath;
- return false;
- }
- return true;
-}
-
-bf::path FindIconPath(const bf::path& base_path, const std::string& pkgid,
- const bf::path& icon_filename,
- const bf::path& root_path) {
- std::vector<bf::path> paths;
- bf::path system_path = base_path / icon_filename;
- bf::path small_system_path = base_path / "default" / "small" / icon_filename;
- bf::path res_path = root_path / pkgid / "res" / "icons" / icon_filename;
-
- paths.push_back(system_path);
- paths.push_back(small_system_path);
- paths.push_back(res_path);
-
- for (auto& path : paths) {
- if (bf::exists(path))
- return path;
- }
-
- return {};
-}
-
-} // namespace
-
namespace common_installer {
namespace filesystem {
return Status::ERROR;
// Change owner of files at root path
- bf::path start_path = context_->pkg_path.get();
- if (!SetOwner(start_path, uid, *gid))
+ if (!ci::SetOwnershipAll(context_->pkg_path.get(), uid, *gid))
return Status::ERROR;
- for (bf::recursive_directory_iterator iter(start_path);
- iter != bf::recursive_directory_iterator(); ++iter) {
- if (bf::is_symlink(symlink_status(iter->path())))
- continue;
- if (!SetOwner(iter->path(), uid, *gid))
- return Status::ERROR;
- }
// For icon files
const char *iconpath = getIconPath(uid, context_->is_preload_request.get());
icon_x* icon = reinterpret_cast<icon_x*>(app->icon->data);
bf::path icon_path = icon->text;
// bf::path base_path = iconpath;
- bf::path found_icon_path = FindIconPath(iconpath,
+ bf::path found_icon_path = GetIconPath(iconpath,
context_->pkgid.get(), icon_path.filename(),
context_->root_application_path.get());
if (!found_icon_path.empty()) {
- if (!SetOwner(found_icon_path, uid, *gid))
+ if (!ci::SetOwnership(found_icon_path, uid, *gid))
return Status::ERROR;
}
}
// Manifest files for global apps
if (!context_->xml_path.get().empty()) {
- if (!SetOwner(context_->xml_path.get(), uid, *gid))
+ if (!ci::SetOwnership(context_->xml_path.get(), uid, *gid))
return Status::ERROR;
}
--- /dev/null
+// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+// 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_recover_change_owner.h"
+
+#include <unistd.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <pkgmgr-info.h>
+#include <cassert>
+
+#include <cstring>
+#include <string>
+#include <vector>
+
+#include "common/paths.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 common_installer {
+namespace filesystem {
+
+Step::Status StepRecoverChangeOwner::RecoveryUpdate() {
+ uid_t uid = context_->uid.get();
+ boost::optional<gid_t> gid = ci::GetGidByUid(uid);
+ if (!gid)
+ return Step::Status::ERROR;
+
+ // Change owner of files at root path
+ if (!ci::SetOwnershipAll(context_->pkg_path.get(), uid, *gid))
+ return Step::Status::ERROR;
+
+ // For icon files
+ const char *iconpath = getIconPath(uid, context_->is_preload_request.get());
+ if (iconpath) {
+ for (application_x* app :
+ GListRange<application_x*>(
+ context_->manifest_data.get()->application)) {
+ if (!app->icon)
+ continue;
+
+ icon_x* icon = reinterpret_cast<icon_x*>(app->icon->data);
+ bf::path icon_path = icon->text;
+ // bf::path base_path = iconpath;
+ bf::path found_icon_path = GetIconPath(iconpath,
+ context_->pkgid.get(), icon_path.filename(),
+ context_->root_application_path.get());
+ if (!found_icon_path.empty()) {
+ if (!ci::SetOwnership(found_icon_path, uid, *gid))
+ return Step::Status::ERROR;
+ }
+ }
+ }
+
+ // Manifest files for global apps
+ if (!context_->xml_path.get().empty()) {
+ if (!ci::SetOwnership(context_->xml_path.get(), uid, *gid))
+ return Step::Status::ERROR;
+ }
+
+ return Step::Status::OK;
+}
+
+} // namespace filesystem
+} // namespace common_installer
+
--- /dev/null
+// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef COMMON_STEP_FILESYSTEM_STEP_RECOVER_CHANGE_OWNER_H_
+#define COMMON_STEP_FILESYSTEM_STEP_RECOVER_CHANGE_OWNER_H_
+
+#include <manifest_parser/utils/logging.h>
+
+#include "common/installer_context.h"
+#include "common/step/recovery/step_recovery.h"
+
+namespace common_installer {
+namespace filesystem {
+
+/**
+ * @brief step responsible for changing ownership.
+ *
+ * Part of Recovery Mode. Is responsible for changing ownership of package
+ * directories during package recovery.
+ * Used by WGT and TPK.
+ */
+class StepRecoverChangeOwner : public recovery::StepRecovery {
+ public:
+ using StepRecovery::StepRecovery;
+
+ Status RecoveryNew() override { return Status::OK; };
+ Status RecoveryUpdate() override;
+
+ STEP_NAME(RecoverChangeOwner)
+};
+
+} // namespace filesystem
+} // namespace common_installer
+
+#endif // COMMON_STEP_FILESYSTEM_STEP_RECOVER_CHANGE_OWNER_H_