2 * Copyright (c) 2012 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 directory_api.cpp
18 * @author Soyoung Kim(sy037.kim@samsung.com)
20 * @brief directory api - implementation file
23 #include <directory_api.h>
27 #include <dpl/log/log.h>
28 #include <dpl/foreach.h>
29 #include <dpl/utils/wrt_utility.h>
31 namespace DirectoryApi {
32 bool DirectoryCopy(std::string source, std::string dest)
34 DIR* dir = opendir(source.c_str());
40 struct dirent *dEntryResult;
45 return_code = readdir_r(dir, &dEntry, &dEntryResult);
46 if (dEntryResult != NULL && return_code == 0) {
47 std::string fileName = dEntry.d_name;
48 std::string fullName = source + "/" + fileName;
50 if (stat(fullName.c_str(), &statInfo) != 0) {
55 if (S_ISDIR(statInfo.st_mode)) {
56 if (("." == fileName) || (".." == fileName)) {
59 std::string destFolder = dest + "/" + fileName;
60 WrtUtilMakeDir(destFolder);
62 if (!DirectoryCopy(fullName, destFolder)) {
68 std::string destFile = dest + "/" + fileName;
69 std::ifstream infile(fullName);
70 std::ofstream outfile(destFile);
71 outfile << infile.rdbuf();
75 } while (dEntryResult != NULL && return_code == 0);