2 * Copyright (c) 2013 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 scoped_dir.cpp
18 * @author Iwanek Tomasz (t.iwanek@samsung.com)
20 * @brief This file is the implementation scoped directory
22 #include <dpl/scoped_dir.h>
23 #include <dpl/errno_string.h>
24 #include <dpl/log/log.h>
27 #include <sys/types.h>
32 bool removeRecusive(const char * path)
37 char * const paths[] = { const_cast<char * const>(path), NULL };
38 if ((fts = fts_open(paths, FTS_PHYSICAL | FTS_NOCHDIR, NULL)) == NULL) {
41 while ((ftsent = fts_read(fts)) != NULL) {
42 switch (ftsent->fts_info) {
46 if (rmdir(ftsent->fts_accpath) != 0) {
56 if (unlink(ftsent->fts_accpath) != 0) {
71 if (fts_close(fts) == -1) {
81 ScopedDirPolicy::Type ScopedDirPolicy::NullValue()
86 void ScopedDirPolicy::Destroy(Type str)
90 bool status = removeRecusive(str.c_str());
93 LogError("Error while removing recursively: " << str);
98 ScopedDir::ScopedDir(const std::string & str, mode_t mode) : BaseType(str)
102 if (mkdir(str.c_str(), mode) == -1)
104 std::string errstr = DPL::GetErrnoString();
105 LogError("Error while creating directory: " << str
106 << " [" << errstr << "]");