1 /* 2 * Copyright (c) 2023 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 /*! 17 * Directory_ex provides an enhanced interface for some file and path related operations. 18 */ 19 20 /// File permissions for the owner of the file (user) - Read, write, and execute. 21 pub const S_IRWXU: u32 = 0o700; 22 23 /// File permissions for the group - Read, write, and execute. 24 pub const S_IRWXG: u32 = 0o070; 25 26 /// File permissions for others (non-owner/non-group members) - Read, write, and execute. 27 pub const S_IRWXO: u32 = 0o007; 28 29 /// File permission for the owner to read. 30 pub const S_IRUSR: u32 = 0o400; 31 32 /// File permission for the group to read. 33 pub const S_IRGRP: u32 = 0o040; 34 35 /// File permission for others (non-owner/non-group members) to read. 36 pub const S_IROTH: u32 = 0o004; 37 38 /// Maximum length of a file path in characters 39 pub const PATH_MAX: usize = 4096; 40 41 #[cxx::bridge(namespace = "OHOS")] 42 /// Module directory_ex::ffi. Includes interfaces which will call c++ counterparts via FFI. 43 pub mod ffi { 44 #[allow(dead_code)] 45 unsafe extern "C++" { 46 include!("commonlibrary/c_utils/base/include/directory_ex.h"); 47 /// Get the full absolute path to the current program. RustGetCurrentProcFullFileName() -> String48 pub fn RustGetCurrentProcFullFileName() -> String; 49 50 /// Get the absolute path of the current program. RustGetCurrentProcPath() -> String51 pub fn RustGetCurrentProcPath() -> String; 52 53 /// Obtain the path to the corresponding file by the full path. RustExtractFilePath(fileFullName: &String) -> String54 pub fn RustExtractFilePath(fileFullName: &String) -> String; 55 56 /// Obtain the name to the corresponding file by the full path. RustExtractFileName(fileFullName: &String) -> String57 pub fn RustExtractFileName(fileFullName: &String) -> String; 58 59 /// Obtain the filename extension to the corresponding file by the full path. RustExtractFileExt(fileName: &String) -> String60 pub fn RustExtractFileExt(fileName: &String) -> String; 61 62 /// Determine whether the path has ended with '/', and returns the path 63 /// after removing '/', otherwise returns the path directly. RustExcludeTrailingPathDelimiter(path: &String) -> String64 pub fn RustExcludeTrailingPathDelimiter(path: &String) -> String; 65 66 /// Determine whether the path has ended with "/", and returns the path 67 /// after adding '/', otherwise returns the path directly. RustIncludeTrailingPathDelimiter(path: &String) -> String68 pub fn RustIncludeTrailingPathDelimiter(path: &String) -> String; 69 70 /// Get names of all files under `path` recursively. RustGetDirFiles(path: &String, files: &mut Vec<String>)71 pub fn RustGetDirFiles(path: &String, files: &mut Vec<String>); 72 73 /// Judge if the path is empty. IsEmptyFolder(path: &CxxString) -> bool74 pub fn IsEmptyFolder(path: &CxxString) -> bool; 75 76 /// If there are problems such as 'Permission Denied', the creation may also fail. ForceCreateDirectory(path: &CxxString) -> bool77 pub fn ForceCreateDirectory(path: &CxxString) -> bool; 78 79 /// Delete the specified dir. ForceRemoveDirectory(path: &CxxString) -> bool80 pub fn ForceRemoveDirectory(path: &CxxString) -> bool; 81 82 /// Remove the file specified by fileName. RemoveFile(fileName: &CxxString) -> bool83 pub fn RemoveFile(fileName: &CxxString) -> bool; 84 85 /// Get the folder size(bytes). GetFolderSize(path: &CxxString) -> u6486 pub fn GetFolderSize(path: &CxxString) -> u64; 87 88 /// Change the file authority. ChangeModeFile(fileName: &CxxString, mode: &u32) -> bool89 pub fn ChangeModeFile(fileName: &CxxString, mode: &u32) -> bool; 90 91 /// Change authority of the directory specified by path and all of its subdirectories. ChangeModeDirectory(path: &CxxString, mode: &u32) -> bool92 pub fn ChangeModeDirectory(path: &CxxString, mode: &u32) -> bool; 93 94 /// Get real path from relative path. RustPathToRealPath(path: &String, realPath: &mut String) -> bool95 pub fn RustPathToRealPath(path: &String, realPath: &mut String) -> bool; 96 } 97 }