• 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__PROXY_FILESYSTEM_H
17 #define CORE__IO__PROXY_FILESYSTEM_H
18 
19 #include <base/containers/string.h>
20 #include <base/containers/string_view.h>
21 #include <base/containers/vector.h>
22 #include <core/io/intf_file_system.h>
23 #include <core/namespace.h>
24 
25 CORE_BEGIN_NAMESPACE()
26 class FileManager;
27 
28 /** File protocol.
29  * Protocol implementation that uses given protocol as proxy to destination uri, for example app:// to point in to
30  * application working directory.
31  */
32 class ProxyFilesystem final : public IFilesystem {
33 public:
34     ProxyFilesystem(FileManager& fileManager, BASE_NS::string_view destination);
35 
36     ProxyFilesystem() = delete;
37     ProxyFilesystem(ProxyFilesystem const&) = delete;
38     ProxyFilesystem& operator=(ProxyFilesystem const&) = delete;
39 
40     ~ProxyFilesystem() override = default;
41 
42     void RemoveSearchPath(BASE_NS::string_view destination);
43 
44     IDirectory::Entry GetEntry(BASE_NS::string_view uri) override;
45     IFile::Ptr OpenFile(BASE_NS::string_view path) override;
46     IFile::Ptr CreateFile(BASE_NS::string_view path) override;
47     bool DeleteFile(BASE_NS::string_view path) override;
48 
49     IDirectory::Ptr OpenDirectory(BASE_NS::string_view path) override;
50     IDirectory::Ptr CreateDirectory(BASE_NS::string_view path) override;
51     bool DeleteDirectory(BASE_NS::string_view path) override;
52 
53     bool Rename(BASE_NS::string_view fromPath, BASE_NS::string_view toPath) override;
54 
55     BASE_NS::vector<BASE_NS::string> GetUriPaths(BASE_NS::string_view uri) const override;
56 
57     void AppendSearchPath(BASE_NS::string_view uri);
58     void PrependSearchPath(BASE_NS::string_view uri);
59 
60 protected:
Destroy()61     void Destroy() override
62     {
63         delete this;
64     }
65 
66 private:
67     FileManager& fileManager_;
68     BASE_NS::vector<BASE_NS::string> destinations_;
69 };
70 CORE_END_NAMESPACE()
71 
72 #endif // CORE__IO__PROXY_FILESYSTEM_H
73