return GetBackupPath(icon_path);
}
+std::string GetIconFileBackupExtension() {
+ return ".bck";
+}
+
} // namespace common_installer
#include <boost/filesystem/path.hpp>
+#include <string>
+
namespace common_installer {
/**
boost::filesystem::path GetBackupPathForIconFile(
const boost::filesystem::path& icon_path);
+/**
+ * @brief GetIconFileBackupExtension
+ * @return extension for backup icon files
+ */
+std::string GetIconFileBackupExtension();
+
} // namespace common_installer
#endif // COMMON_BACKUP_PATHS_H_
#include <boost/filesystem.hpp>
#include <boost/system/error_code.hpp>
+#include <string>
+
#include "common/backup_paths.h"
#include "common/utils/file_util.h"
#include "common/utils/glist_range.h"
namespace backup {
Step::Status StepBackupIcons::process() {
- std::vector<bf::path> paths { getIconPath(context_->uid.get()) };
- return MoveIcons(paths);
-}
-
-Step::Status StepBackupIcons::clean() {
- RemoveBackupIcons();
- LOG(DEBUG) << "Icons backup removed";
- return Status::OK;
-}
-
-Step::Status StepBackupIcons::undo() {
- for (auto& pair : icons_) {
- if (!MoveFile(pair.second, pair.first)) {
- LOG(ERROR) << "Cannot revert icon from backup: " << pair.first;
- return Status::ICON_ERROR;
- }
- }
- LOG(DEBUG) << "Icons reverted from backup";
- return Status::OK;
-}
-
-Step::Status StepBackupIcons::MoveIcons(
- const std::vector<boost::filesystem::path>& sources) {
// gather icon info
- for (application_x* app :
- GListRange<application_x*>(
- context_->old_manifest_data.get()->application)) {
- for (const auto& source : sources) {
- bf::path source_path = source / bf::path(app->appid);
+ for (auto iter = bf::directory_iterator(getIconPath(context_->uid.get()));
+ iter != bf::directory_iterator(); ++iter) {
+ if (!bf::is_regular_file(iter->path()))
+ continue;
+ for (application_x* app : GListRange<application_x*>(
+ context_->old_manifest_data.get()->application)) {
if (app->icon) {
- icon_x* icon = reinterpret_cast<icon_x*>(app->icon->data);
- if (!icon->text) {
- LOG(ERROR) << "Icon text is not set";
- return Status::ICON_NOT_FOUND;
+ std::string filename = iter->path().filename().string();
+ if (filename.find(app->appid) == 0) {
+ bf::path icon_backup = GetBackupPathForIconFile(iter->path());
+ icons_.emplace_back(iter->path(), icon_backup);
}
- source_path += bf::path(icon->text).extension();
- } else {
- source_path += ".png";
}
- bf::path icon_backup = GetBackupPathForIconFile(source_path);
- if (bf::exists(source_path))
- icons_.emplace_back(source_path, icon_backup);
}
}
return Status::OK;
}
+Step::Status StepBackupIcons::clean() {
+ RemoveBackupIcons();
+ LOG(DEBUG) << "Icons backup removed";
+ return Status::OK;
+}
+
+Step::Status StepBackupIcons::undo() {
+ for (auto& pair : icons_) {
+ if (!MoveFile(pair.second, pair.first)) {
+ LOG(ERROR) << "Cannot revert icon from backup: " << pair.first;
+ return Status::ICON_ERROR;
+ }
+ }
+ LOG(DEBUG) << "Icons reverted from backup";
+ return Status::OK;
+}
+
void StepBackupIcons::RemoveBackupIcons() {
for (auto& pair : icons_) {
bs::error_code error;
*/
Status precheck() override { return Status::OK; }
- protected:
- Status MoveIcons(const std::vector<boost::filesystem::path>& sources);
-
private:
void RemoveBackupIcons();
namespace common_installer {
namespace filesystem {
-Step::Status StepCreateIcons::process() {
- std::vector<bf::path> paths { getIconPath(context_->uid.get()) };
- return CopyIcons(paths);
-}
-
Step::Status StepCreateIcons::undo() {
for (auto& icon : icons_) {
bs::error_code error;
return Status::OK;
}
-Step::Status StepCreateIcons::CopyIcons(
- const std::vector<bf::path>& destinations) {
+Step::Status StepCreateIcons::process() {
+ bf::path destination = getIconPath(context_->uid.get());
+ bs::error_code error;
+ if (!bf::exists(destination)) {
+ bf::create_directories(destination, error);
+ if (error) {
+ LOG(ERROR) << "Cannot create directory of application icons: "
+ << destination;
+ return Status::ERROR;
+ }
+ }
+
for (application_x* app :
GListRange<application_x*>(context_->manifest_data.get()->application)) {
- if (GetAppTypeForIcons() != app->type)
- continue;
- // TODO(t.iwanek): this is ignoring icon locale as well as other steps
- // icons should be localized
+ // TODO(t.iwanek): this ignores icon locale as well in same way as other
+ // steps -> icons should be localized
if (app->icon) {
icon_x* icon = reinterpret_cast<icon_x*>(app->icon->data);
- bf::path source = GetIconRoot() / icon->text;
+ bf::path source(icon->text);
if (bf::exists(source)) {
- for (const auto& destination : destinations) {
- bs::error_code error;
- if (!bf::exists(destination)) {
- bf::create_directories(destination, error);
- if (error) {
- LOG(ERROR) << "Cannot create directory of application icons: "
- << destination;
- return Status::ERROR;
- }
- }
- bf::path destination_path = destination / app->appid;
- if (source.has_extension())
- destination_path += source.extension();
- else
- destination_path += ".png";
- bf::copy_file(source, destination_path, error);
- if (error) {
- LOG(ERROR) << "Cannot create package icon: " << destination_path;
- return Status::ICON_ERROR;
- }
- icons_.push_back(destination_path);
+ bf::path destination_path = destination / app->appid;
+ if (source.has_extension())
+ destination_path += source.extension();
+ else
+ destination_path += ".png";
+ bf::copy_file(source, destination_path, error);
+ if (error) {
+ LOG(ERROR) << "Cannot create package icon: " << destination_path
+ << " , error: " << error;
+ return Status::ICON_ERROR;
}
+ icons_.push_back(destination_path);
}
}
}
return Status::OK;
}
-boost::filesystem::path StepCreateIcons::GetIconRoot() const {
- // TODO(t.iwanek): shared/res is location of icons for tpk
- return context_->pkg_path.get() / "shared" / "res";
-}
-
-std::string StepCreateIcons::GetAppTypeForIcons() const {
- return "capp";
-}
-
} // namespace filesystem
} // namespace common_installer
*/
Status precheck() override { return Status::OK; }
- protected:
- Status CopyIcons(const std::vector<boost::filesystem::path>& destinations);
- virtual boost::filesystem::path GetIconRoot() const;
- virtual std::string GetAppTypeForIcons() const;
-
private:
std::vector<boost::filesystem::path> icons_;
return Status::OK;
}
-std::vector<boost::filesystem::path> StepRecoverIcons::GetIconsPaths() {
- std::vector<bf::path> paths { getIconPath(context_->uid.get()) };
- return paths;
-}
-
bool StepRecoverIcons::TryGatherIcons() {
if (!context_->manifest_data.get())
return false;
- for (application_x* app :
- GListRange<application_x*>(context_->manifest_data.get()->application)) {
- for (const auto& path : GetIconsPaths()) {
- bf::path icon_path = path / bf::path(app->appid);
+
+ // gather icon info
+ for (auto iter = bf::directory_iterator(getIconPath(context_->uid.get()));
+ iter != bf::directory_iterator(); ++iter) {
+ if (!bf::is_regular_file(iter->path()))
+ continue;
+ for (application_x* app : GListRange<application_x*>(
+ context_->manifest_data.get()->application)) {
if (app->icon) {
- icon_x* icon = reinterpret_cast<icon_x*>(app->icon->data);
- icon_path += bf::path(icon->text).extension();
- } else {
- icon_path += ".png";
+ bf::path p = iter->path();
+ std::string filename = iter->path().filename().string();
+ if (filename.find(app->appid) == 0) {
+ bf::path icon;
+ bf::path icon_backup;
+ if (p.extension() == GetIconFileBackupExtension()) {
+ icon_backup = p;
+ icon = p.replace_extension("");
+ } else {
+ icon = p;
+ icon_backup = GetBackupPathForIconFile(iter->path());
+ }
+ icons_.insert(std::make_pair(icon, icon_backup));
+ }
}
- bf::path icon_backup = GetBackupPathForIconFile(icon_path);
- if (bf::exists(icon_backup) || bf::exists(icon_path))
- icons_.emplace_back(icon_path, icon_backup);
}
}
return true;
#include <manifest_parser/utils/logging.h>
+#include <set>
+#include <string>
#include <utility>
-#include <vector>
#include "common/installer_context.h"
#include "common/step/step_recovery.h"
Status RecoveryNew() override;
Status RecoveryUpdate() override;
- protected:
- virtual std::vector<boost::filesystem::path> GetIconsPaths();
-
private:
bool TryGatherIcons();
- std::vector<std::pair<boost::filesystem::path, boost::filesystem::path>>
+ std::set<std::pair<boost::filesystem::path, boost::filesystem::path>>
icons_;
SCOPE_LOG_TAG(RecoverIcons)
#include <pkgmgr-info.h>
#include <cstring>
+#include <string>
#include "common/backup_paths.h"
#include "common/utils/file_util.h"
}
Step::Status StepRemoveIcons::process() {
- for (application_x* app :
- GListRange<application_x*>(context_->manifest_data.get()->application)) {
- bf::path app_icon = bf::path(getIconPath(context_->uid.get()))
- / bf::path(app->appid);
- if (app->icon) {
- icon_x* icon = reinterpret_cast<icon_x*>(app->icon->data);
- app_icon += bf::path(icon->text).extension();
- } else {
- app_icon += ".png";
- }
- if (bf::exists(app_icon)) {
- bf::path backup_icon_file = GetBackupPathForIconFile(app_icon);
- if (!MoveFile(app_icon, backup_icon_file)) {
- LOG(ERROR) << "Failed to create backup for icon: " << app_icon;
- return Status::ICON_ERROR;
+ for (auto iter = bf::directory_iterator(getIconPath(context_->uid.get()));
+ iter != bf::directory_iterator(); ++iter) {
+ if (!bf::is_regular_file(iter->path()))
+ continue;
+ for (application_x* app :
+ GListRange<application_x*>(
+ context_->manifest_data.get()->application)) {
+ if (app->icon) {
+ std::string filename = iter->path().filename().string();
+ if (filename.find(app->appid) == 0) {
+ bf::path icon_backup = GetBackupPathForIconFile(iter->path());
+ backups_.emplace_back(iter->path(), icon_backup);
+ }
}
- backups_.emplace_back(backup_icon_file, app_icon);
}
}
return Status::OK;