• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef CORE__IO__OHOS_FILESYSTEM_H
17 #define CORE__IO__OHOS_FILESYSTEM_H
18 
19 #include <base/containers/string.h>
20 #include <base/containers/string_view.h>
21 #include <base/containers/vector.h>
22 #include <base/containers/unordered_map.h>
23 #include <base/namespace.h>
24 #include <core/io/intf_directory.h>
25 #include <core/io/intf_file.h>
26 #include <core/io/intf_file_system.h>
27 #include <core/namespace.h>
28 
29 #include "ohos_file.h"
30 
31 CORE_BEGIN_NAMESPACE()
32 class FileManager;
33 
34 class OhosFilesystem final : public IFilesystem {
35 public:
36     OhosFilesystem(const BASE_NS::string_view hapPath, const BASE_NS::string_view bundleName,
37         const BASE_NS::string_view moduleName);
38     OhosFilesystem() = delete;
39     OhosFilesystem(OhosFilesystem const&) = delete;
40     OhosFilesystem& operator=(OhosFilesystem const&) = delete;
41     ~OhosFilesystem() override = default;
42 
43     IDirectory::Entry GetEntry(BASE_NS::string_view path) override;
44     IFile::Ptr CreateFile(BASE_NS::string_view path) override;
45     bool DeleteFile(BASE_NS::string_view path) override;
46     IDirectory::Ptr OpenDirectory(BASE_NS::string_view path) override;
47     IDirectory::Ptr CreateDirectory(BASE_NS::string_view path) override;
48     bool DeleteDirectory(BASE_NS::string_view path) override;
49     bool Rename(BASE_NS::string_view fromPath, BASE_NS::string_view toPath) override;
50     BASE_NS::vector<BASE_NS::string> GetUriPaths(BASE_NS::string_view uri) const override;
51     IFile::Ptr OpenFile(BASE_NS::string_view path) override;
52 
53 protected:
54     BASE_NS::string ValidatePath(const BASE_NS::string_view pathIn) const;
Destroy()55     void Destroy() override
56     {
57         delete this;
58     }
59 
60     PlatformHapInfo hapInfo_;
61     BASE_NS::unordered_map<BASE_NS::string, std::weak_ptr<OhosFileStorage>> ohosFiles_;
62     BASE_NS::refcnt_ptr<OhosResMgr> resManager_ = nullptr;
63 };
64 CORE_END_NAMESPACE()
65 #endif