1 // Copyright (c) 2023 Huawei Device Co., Ltd. 2 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // you may not use this file except in compliance with the License. 4 // You may obtain a copy of the License at 5 // 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 //! Directory_ex provides an enhanced interface for some file and path related 15 //! operations. 16 17 /// File permissions for the owner of the file (user) - Read, write, and 18 /// execute. 19 pub const S_IRWXU: u32 = 0o700; 20 21 /// File permissions for the group - Read, write, and execute. 22 pub const S_IRWXG: u32 = 0o070; 23 24 /// File permissions for others (non-owner/non-group members) - Read, write, and 25 /// execute. 26 pub const S_IRWXO: u32 = 0o007; 27 28 /// File permission for the owner to read. 29 pub const S_IRUSR: u32 = 0o400; 30 31 /// File permission for the group to read. 32 pub const S_IRGRP: u32 = 0o040; 33 34 /// File permission for others (non-owner/non-group members) to read. 35 pub const S_IROTH: u32 = 0o004; 36 37 /// Maximum length of a file path in characters 38 pub const PATH_MAX: usize = 4096; 39 40 #[cxx::bridge(namespace = "OHOS")] 41 /// Module directory_ex::ffi. Includes interfaces which will call c++ 42 /// 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 60 /// path. RustExtractFileExt(fileName: &String) -> String61 pub fn RustExtractFileExt(fileName: &String) -> String; 62 63 /// Determine whether the path has ended with '/', and returns the path 64 /// after removing '/', otherwise returns the path directly. RustExcludeTrailingPathDelimiter(path: &String) -> String65 pub fn RustExcludeTrailingPathDelimiter(path: &String) -> String; 66 67 /// Determine whether the path has ended with "/", and returns the path 68 /// after adding '/', otherwise returns the path directly. RustIncludeTrailingPathDelimiter(path: &String) -> String69 pub fn RustIncludeTrailingPathDelimiter(path: &String) -> String; 70 71 /// Get names of all files under `path` recursively. RustGetDirFiles(path: &String, files: &mut Vec<String>)72 pub fn RustGetDirFiles(path: &String, files: &mut Vec<String>); 73 74 /// Judge if the path is empty. IsEmptyFolder(path: &CxxString) -> bool75 pub fn IsEmptyFolder(path: &CxxString) -> bool; 76 77 /// If there are problems such as 'Permission Denied', the creation may 78 /// also fail. ForceCreateDirectory(path: &CxxString) -> bool79 pub fn ForceCreateDirectory(path: &CxxString) -> bool; 80 81 /// Delete the specified dir. ForceRemoveDirectory(path: &CxxString) -> bool82 pub fn ForceRemoveDirectory(path: &CxxString) -> bool; 83 84 /// Remove the file specified by fileName. RemoveFile(fileName: &CxxString) -> bool85 pub fn RemoveFile(fileName: &CxxString) -> bool; 86 87 /// Get the folder size(bytes). GetFolderSize(path: &CxxString) -> u6488 pub fn GetFolderSize(path: &CxxString) -> u64; 89 90 /// Change the file authority. ChangeModeFile(fileName: &CxxString, mode: &u32) -> bool91 pub fn ChangeModeFile(fileName: &CxxString, mode: &u32) -> bool; 92 93 /// Change authority of the directory specified by path and all of its 94 /// subdirectories. ChangeModeDirectory(path: &CxxString, mode: &u32) -> bool95 pub fn ChangeModeDirectory(path: &CxxString, mode: &u32) -> bool; 96 97 /// Get real path from relative path. RustPathToRealPath(path: &String, realPath: &mut String) -> bool98 pub fn RustPathToRealPath(path: &String, realPath: &mut String) -> bool; 99 } 100 } 101