1 /* 2 * Copyright (c) 2024 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 API_CORE_IO_IFILESYSTEM_H 17 #define API_CORE_IO_IFILESYSTEM_H 18 19 #include <base/containers/string.h> 20 #include <base/containers/string_view.h> 21 #include <base/containers/unique_ptr.h> 22 #include <base/containers/vector.h> 23 #include <base/namespace.h> 24 #include <core/io/intf_directory.h> 25 #include <core/io/intf_file.h> 26 #include <core/namespace.h> 27 CORE_BEGIN_NAMESPACE()28CORE_BEGIN_NAMESPACE() 29 /** @ingroup group_io_ifilesystem */ 30 /** IFilesystem */ 31 class IFilesystem { 32 public: 33 /** Get directory entry from uri 34 * @param uri Path to file 35 * @return IDirectory::Entry defining entry type , size and timestamp. 36 */ 37 virtual IDirectory::Entry GetEntry(BASE_NS::string_view uri) = 0; 38 39 /** Opens file from designated path 40 * @param path Path to file 41 */ 42 virtual IFile::Ptr OpenFile(BASE_NS::string_view path) = 0; 43 44 /** Creates file to given path 45 * @param path Path where file is created 46 */ 47 virtual IFile::Ptr CreateFile(BASE_NS::string_view path) = 0; 48 49 /** Deletes file from given path 50 * @param path Path to file 51 */ 52 virtual bool DeleteFile(BASE_NS::string_view path) = 0; 53 54 /** Opens directory 55 * @param path Path to directory for opening 56 */ 57 virtual IDirectory::Ptr OpenDirectory(BASE_NS::string_view path) = 0; 58 59 /** Creates a directory 60 * @param path Path where directory is created 61 */ 62 virtual IDirectory::Ptr CreateDirectory(BASE_NS::string_view path) = 0; 63 64 /** Deletes directory from given path 65 * @param path Path to directory 66 */ 67 virtual bool DeleteDirectory(BASE_NS::string_view path) = 0; 68 69 /** Renames file or directory from given path to another path 70 * @param fromPath Path to file or directory to be renamed 71 * @param toPath Path with destination name 72 */ 73 virtual bool Rename(BASE_NS::string_view fromPath, BASE_NS::string_view toPath) = 0; 74 75 /** Resolves all files which uri might be pointing to 76 * @param uri Uri to resolve 77 */ 78 virtual BASE_NS::vector<BASE_NS::string> GetUriPaths(BASE_NS::string_view uri) const = 0; 79 80 struct Deleter { 81 constexpr Deleter() noexcept = default; 82 void operator()(IFilesystem* ptr) const 83 { 84 ptr->Destroy(); 85 } 86 }; 87 using Ptr = BASE_NS::unique_ptr<IFilesystem, Deleter>; 88 89 protected: 90 IFilesystem() = default; 91 virtual ~IFilesystem() = default; 92 virtual void Destroy() = 0; 93 }; 94 CORE_END_NAMESPACE() 95 96 #endif // API_CORE_IO_IFILESYSTEM_H 97