Left: | ||
Right: |
OLD | NEW |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 #ifndef ADBLOCK_PLUS_FILE_SYSTEM_H | 18 #ifndef ADBLOCK_PLUS_FILE_SYSTEM_H |
19 #define ADBLOCK_PLUS_FILE_SYSTEM_H | 19 #define ADBLOCK_PLUS_FILE_SYSTEM_H |
20 | 20 |
21 #include <istream> | 21 #include <istream> |
22 #include <stdint.h> | 22 #include <stdint.h> |
23 #include <string> | 23 #include <string> |
24 #include <memory> | 24 #include <memory> |
25 | 25 |
26 #include "IFileSystem.h" | |
27 | |
26 namespace AdblockPlus | 28 namespace AdblockPlus |
27 { | 29 { |
28 /** | 30 /** |
29 * File system interface. | 31 * File system interface. |
30 */ | 32 */ |
31 class FileSystem | 33 class FileSystem |
32 { | 34 { |
33 public: | 35 public: |
34 /** | |
35 * Result of a stat operation, i.e.\ information about a file. | |
36 */ | |
37 struct StatResult | |
38 { | |
39 StatResult() | |
40 { | |
41 exists = false; | |
42 isDirectory = false; | |
43 isFile = false; | |
44 lastModified = 0; | |
45 } | |
46 | |
47 /** | |
48 * File exists. | |
49 */ | |
50 bool exists; | |
51 | |
52 /** | |
53 * File is a directory. | |
54 */ | |
55 bool isDirectory; | |
56 | |
57 /** | |
58 * File is a regular file. | |
59 */ | |
60 bool isFile; | |
61 | |
62 /** | |
63 * POSIX time of the last modification. | |
64 */ | |
65 int64_t lastModified; | |
66 }; | |
67 | |
68 virtual ~FileSystem() {} | 36 virtual ~FileSystem() {} |
69 | 37 |
70 /** | 38 /** |
71 * Reads from a file. | 39 * Reads from a file. |
72 * @param path File path. | 40 * @param path File path. |
73 * @return Input stream with the file's contents. | 41 * @return Input stream with the file's contents. |
74 */ | 42 */ |
75 virtual std::shared_ptr<std::istream> | 43 virtual std::shared_ptr<std::istream> |
76 Read(const std::string& path) const = 0; | 44 Read(const std::string& path) const = 0; |
77 | 45 |
78 /** | 46 /** |
79 * Writes to a file. | 47 * Writes to a file. |
80 * @param path File path. | 48 * @param path File path. |
81 * @param data Input stream with the data to write. | 49 * @param data Output stream with the data to write. |
82 */ | 50 */ |
83 virtual void Write(const std::string& path, | 51 virtual void Write(const std::string& path, |
84 std::istream& data) = 0; | 52 std::ostream& data) = 0; |
sergei
2017/07/06 14:14:04
What do you think about making it in a separate co
hub
2017/07/06 14:33:31
This is needed because we write to that stream buf
sergei
2017/07/06 14:53:33
I see, but if we changed either std::istream or st
hub
2017/07/06 21:24:29
See https://codereview.adblockplus.org/29481704
| |
85 | 53 |
86 /** | 54 /** |
87 * Moves a file (i.e.\ renames it). | 55 * Moves a file (i.e.\ renames it). |
88 * @param fromPath Current path to the file. | 56 * @param fromPath Current path to the file. |
89 * @param toPath New path to the file. | 57 * @param toPath New path to the file. |
90 */ | 58 */ |
91 virtual void Move(const std::string& fromPath, | 59 virtual void Move(const std::string& fromPath, |
92 const std::string& toPath) = 0; | 60 const std::string& toPath) = 0; |
93 | 61 |
94 /** | 62 /** |
95 * Removes a file. | 63 * Removes a file. |
96 * @param path File path. | 64 * @param path File path. |
97 */ | 65 */ |
98 virtual void Remove(const std::string& path) = 0; | 66 virtual void Remove(const std::string& path) = 0; |
99 | 67 |
100 /** | 68 /** |
101 * Retrieves information about a file. | 69 * Retrieves information about a file. |
102 * @param path File path. | 70 * @param path File path. |
103 * @return File information. | 71 * @return File information. |
104 */ | 72 */ |
105 virtual StatResult Stat(const std::string& path) const = 0; | 73 virtual IFileSystem::StatResult Stat(const std::string& path) const = 0; |
106 | 74 |
107 /** | 75 /** |
108 * Returns the absolute path to a file. | 76 * Returns the absolute path to a file. |
109 * @param path File path (can be relative or absolute). | 77 * @param path File path (can be relative or absolute). |
110 * @return Absolute file path. | 78 * @return Absolute file path. |
111 */ | 79 */ |
112 virtual std::string Resolve(const std::string& path) const = 0; | 80 virtual std::string Resolve(const std::string& path) const = 0; |
113 }; | 81 }; |
114 | 82 |
115 /** | 83 /** |
116 * Shared smart pointer to a `FileSystem` instance. | 84 * Shared smart pointer to a `FileSystem` instance. |
117 */ | 85 */ |
118 typedef std::shared_ptr<FileSystem> FileSystemPtr; | 86 typedef std::shared_ptr<FileSystem> FileSystemSyncPtr; |
119 } | 87 } |
120 | 88 |
121 #endif | 89 #endif |
OLD | NEW |