• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2022 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 
16 #include "os/filesystem.h"
17 
18 #if defined PANDA_TARGET_MOBILE || defined PANDA_TARGET_UNIX || defined PANDA_TARGET_ARM32 || \
19     defined PANDA_TARGET_ARM64
20 #include <sys/stat.h>
21 #endif
22 #if defined(PANDA_TARGET_WINDOWS)
23 #include <fileapi.h>
24 #endif
25 
26 #include "utils/logger.h"
27 
28 namespace panda::os {
29 
CreateDirectories(const std::string & folder_name)30 void CreateDirectories(const std::string &folder_name)
31 {
32 #if defined(PANDA_TARGET_MOBILE) || defined(IOS_PLATFORM)
33     constexpr auto DIR_PERMISSIONS = 0775;
34     mkdir(folder_name.c_str(), DIR_PERMISSIONS);
35 #elif defined(PANDA_TARGET_MACOS) || defined(PANDA_TARGET_OHOS)
36     std::filesystem::create_directories(std::filesystem::path(folder_name));
37 #elif defined(PANDA_TARGET_WINDOWS)
38     CreateDirectory(folder_name.c_str(), NULL);
39 #else
40     constexpr auto DIR_PERMISSIONS = 0775;
41     auto status = mkdir(folder_name.c_str(), DIR_PERMISSIONS);
42     if (status != 0) {
43         LOG(WARNING, COMMON) << "Failed to create directory \"" << folder_name.c_str() << "\"\n";
44         LOG(WARNING, COMMON) << "Return status :" << status << "\n";
45     }
46 #endif
47 }
48 
49 }  // namespace panda::os
50