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 view_logic_storage_support.cpp
18 * @author Pawel Sikorski (p.sikorski@samsung.com)
19 * @brief Implementation file of StorageSupport API used by ViewLogic
21 #include "view_logic_storage_support.h"
26 #include <dpl/assert.h>
27 #include <dpl/exception.h>
28 #include <dpl/log/log.h>
29 #include <dpl/string.h>
30 #include <dpl/utils/wrt_utility.h>
31 #include <widget_model.h>
33 namespace ViewModule {
34 namespace StorageSupport {
35 namespace { //anonymous
36 const mode_t TEMPORARY_STORAGE_MODE = 0700;
37 static bool rootDirectory = true;
39 static int removeFile(const char* path, const struct stat* /*sb*/, int tflag)
42 LogError("Wrong input path");
46 std::string inputPath = path;
49 LogDebug("Skip root directory");
50 rootDirectory = false;
54 if (tflag == FTW_F || tflag == FTW_D) {
55 if (!WrtUtilRemove(inputPath)) {
56 LogError("Fail to remove");
58 } else if (tflag == FTW_DNR) {
59 LogError("This is directory which can't be read");
60 } else if (tflag == FTW_NS) {
61 LogError("Unknow error");
67 bool removeDirectory(const char* path)
70 if (ftw(path, removeFile, 20) != 0) {
77 void initializeStorage(WidgetModel *widgetModel)
79 LogDebug("initializeStorage");
80 Assert(widgetModel && "Passed widgetModel is NULL!");
82 // create temporary storage
84 DPL::ToUTF8String(widgetModel->TemporaryStoragePath.Get());
85 if (!WrtUtilDirExists(path)) {
86 if (!WrtUtilMakeDir(path, TEMPORARY_STORAGE_MODE)) {
87 ThrowMsg(DPL::CommonException::InternalError,
88 "Fail to initialize temporary storage");
93 void deinitializeStorage(WidgetModel *widgetModel)
95 LogDebug("deinitializeStorage");
96 Assert(widgetModel && "Passed widgetModel is NULL!");
98 // clean-up temporary storage
100 DPL::ToUTF8String(widgetModel->TemporaryStoragePath.Get());
101 if (!removeDirectory(path.c_str())) {
102 LogError("Fail to deinitialize temporary storage");
105 } // namespace StorageSupport
106 } // namespace ViewModule