• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (C) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include <unistd.h>
16 #include <sys/stat.h>
17 #include "util/file_utils.h"
18 using namespace std;
19 namespace OHOS {
20 namespace HiviewDFX {
FileUtils()21 FileUtils::FileUtils()
22 {
23 }
~FileUtils()24 FileUtils::~FileUtils()
25 {
26 }
CreateFolder(const string & path)27 bool FileUtils::CreateFolder(const string &path)
28 {
29     if (!access(path.c_str(), F_OK) || path == "") {
30         return true;
31     }
32 
33     size_t pos = path.rfind("/");
34     if (pos == string::npos) {
35         return false;
36     }
37 
38     string upperPath = path.substr(0, pos);
39     if (CreateFolder(upperPath)) {
40         if (mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IRWXO)) {
41             if (errno != EEXIST) {
42                 return false;
43             }
44         }
45         return true;
46     }
47     return false;
48 }
49 } // namespace HiviewDFX
50 } // namespace OHOS