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/log/log.h>
26 #include <sys/types.h>
31 bool removeRecusive(const char * path)
36 char * const paths[] = { const_cast<char * const>(path), NULL };
37 if ((fts = fts_open(paths, FTS_PHYSICAL | FTS_NOCHDIR, NULL)) == NULL) {
40 while ((ftsent = fts_read(fts)) != NULL) {
41 switch (ftsent->fts_info) {
45 if (rmdir(ftsent->fts_accpath) != 0) {
55 if (unlink(ftsent->fts_accpath) != 0) {
70 if (fts_close(fts) == -1) {
80 ScopedDirPolicy::Type ScopedDirPolicy::NullValue()
85 void ScopedDirPolicy::Destroy(Type str)
89 bool status = removeRecusive(str.c_str());
92 LogError("Error while removing recursively: " << str);
97 ScopedDir::ScopedDir(const std::string & str, mode_t mode) : BaseType(str)
101 mkdir(str.c_str(), mode);