#include <dpl/string.h>
#include <dpl/log/log.h>
#include <dpl/foreach.h>
+#include <dpl/utils/wrt_utility.h>
#include <widget_install/widget_install_context.h>
#include <widget_install/widget_install_errors.h>
ThrowMsg(Exceptions::RDSDeltaFailure, "File is missed " << filePath);
}
}
+
+std::string parseSubPath(const std::string& filePath)
+{
+ std::string subPath("");
+ size_t pos = filePath.find_last_of('/') + 1;
+
+ if (pos != std::string::npos) {
+ subPath = filePath.substr(0, pos);
+ }
+ return subPath;
+}
+
+void createDir(const std::string& path)
+{
+ if (WrtUtilMakeDir(path)) {
+ LogDebug("Create directory : " << path);
+ } else {
+ ThrowMsg(Exceptions::RDSDeltaFailure, "Fail to create dir" << path);
+ }
}
+} // namespace anonymous
TaskPrepareReinstall::TaskPrepareReinstall(InstallerContext& context) :
DPL::TaskDecl<TaskPrepareReinstall>(this),
newfile += *file;
std::string destPath = m_installedPath;
destPath += *file;
- if (rename(newfile.c_str(), destPath.c_str()) != 0) {
- ThrowMsg(Exceptions::RDSDeltaFailure,
- "Fail to ADD file " << newfile);
+
+ if (WrtUtilDirExists(newfile)) {
+ // In case of a new directory
+ createDir(destPath);
+ } else {
+ // In case of a new file
+
+ // Parse directory and file separately
+ std::string subPath = parseSubPath(destPath);
+ if (subPath.empty()) {
+ ThrowMsg(Exceptions::RDSDeltaFailure,
+ "Invalid path given" << destPath);
+ }
+
+ // Create a new directory
+ createDir(subPath);
+
+ // Add file
+ if (rename(newfile.c_str(), destPath.c_str()) != 0) {
+ ThrowMsg(Exceptions::RDSDeltaFailure,
+ "Fail to add file " << newfile);
+ }
+ LogDebug("Add " << newfile << " to " << destPath);
}
- LogDebug("Copy " << newfile << " to " << destPath);
}
}