• 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 
16 #ifndef DIRECTORY_UTILS_H
17 #define DIRECTORY_UTILS_H
18 
19 #include <string>
20 #include <sys/stat.h>
21 #include "visibility.h"
22 
23 namespace OHOS {
24 namespace DistributedKv {
25 class DirectoryUtils {
26 public:
27     KVSTORE_API static bool ChangeModeFileOnly(const std::string &path, const mode_t &mode);
28 
29     KVSTORE_API static bool ChangeModeDirOnly(const std::string &path, const mode_t &mode);
30 
31     KVSTORE_API static bool CreateDirectory(const std::string &path);
32 
33 private:
34     DirectoryUtils() = default;
35 
36     ~DirectoryUtils() = default;
37 
38     static std::string ExcludeDelimiterAtPathTail(const std::string &path);
39 
40     static std::string IncludeDelimiterAtPathTail(const std::string &path);
41 
42     // change the mode of the specified file or directory.
ChangeMode(const std::string & name,const mode_t & mode)43     static inline bool ChangeMode(const std::string &name, const mode_t &mode)
44     {
45         return (chmod(name.c_str(), mode) == 0);
46     }
47 };
48 } // namespace DistributedKv
49 } // namespace OHOS
50 #endif // DIRECTORY_UTILS_H
51