2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file task_commons.cpp
18 * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
22 #include "task_commons.h"
28 #include <dpl/wrt-dao-ro/global_config.h>
29 #include <dpl/log/log.h>
30 #include <dpl/exception.h>
31 #include <dpl/errno_string.h>
32 #include <dpl/utils/wrt_utility.h>
33 #include <widget_install/widget_install_errors.h>
36 namespace WidgetInstall {
40 const char * const TEMPORARY_PATH_POSTFIX = "temp";
41 const mode_t TEMPORARY_PATH_MODE = 0775;
46 std::string createTempPath(bool preload)
48 LogInfo("Step: Creating temporary path");
51 std::ostringstream tempPathBuilder;
54 tempPathBuilder << WrtDB::GlobalConfig::GetUserPreloadedWidgetPath();
56 tempPathBuilder << WrtDB::GlobalConfig::GetUserInstalledWidgetPath();
58 tempPathBuilder << WrtDB::GlobalConfig::GetTmpDirPath();
59 tempPathBuilder << "/";
60 tempPathBuilder << TEMPORARY_PATH_POSTFIX;
61 tempPathBuilder << "_";
64 gettimeofday(&tv, NULL);
66 (static_cast<unsigned long long>(tv.tv_sec) * 1000000ULL +
67 static_cast<unsigned long long>(tv.tv_usec));
69 std::string tempPath = tempPathBuilder.str();
71 // Remove old path if any
74 if (stat(tempPath.c_str(), &fileInfo) == 0) {
75 if(!WrtUtilRemove(tempPath)){
76 ThrowMsg(Exceptions::RemovingFolderFailure,
77 "Failed to to remove temporary directory");
81 if(!WrtUtilMakeDir(tempPath, TEMPORARY_PATH_MODE)){
82 ThrowMsg(Exceptions::InternalError, "Failed to create temporary directory");
88 void createTempPath(const std::string& path)
90 if(!WrtUtilMakeDir(path, TEMPORARY_PATH_MODE)){
91 ThrowMsg(Exceptions::InternalError, "Failed to create temporary directory");