OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 // It DCHECKs and returns false if the path points to a folder or a | 95 // It DCHECKs and returns false if the path points to a folder or a |
96 // non-existent file. | 96 // non-existent file. |
97 virtual bool DeleteFile(const Pathname &filename) = 0; | 97 virtual bool DeleteFile(const Pathname &filename) = 0; |
98 | 98 |
99 // This will attempt to delete the empty folder located at 'folder' | 99 // This will attempt to delete the empty folder located at 'folder' |
100 // It DCHECKs and returns false if the path points to a file or a non-existent | 100 // It DCHECKs and returns false if the path points to a file or a non-existent |
101 // folder. It fails normally if the folder is not empty or can otherwise | 101 // folder. It fails normally if the folder is not empty or can otherwise |
102 // not be deleted. | 102 // not be deleted. |
103 virtual bool DeleteEmptyFolder(const Pathname &folder) = 0; | 103 virtual bool DeleteEmptyFolder(const Pathname &folder) = 0; |
104 | 104 |
105 // This will call IterateDirectory, to get a directory iterator, and then | |
106 // call DeleteFolderAndContents and DeleteFile on every path contained in this | |
107 // folder. If the folder is empty, this returns true. | |
108 virtual bool DeleteFolderContents(const Pathname &folder); | |
109 | |
110 // This deletes the contents of a folder, recursively, and then deletes | |
111 // the folder itself. | |
112 virtual bool DeleteFolderAndContents(const Pathname& folder); | |
113 | |
114 // Creates a directory. This will call itself recursively to create /foo/bar | 105 // Creates a directory. This will call itself recursively to create /foo/bar |
115 // even if /foo does not exist. Returns true if the function succeeds. | 106 // even if /foo does not exist. Returns true if the function succeeds. |
116 virtual bool CreateFolder(const Pathname &pathname) = 0; | 107 virtual bool CreateFolder(const Pathname &pathname) = 0; |
117 | 108 |
118 // This moves a file from old_path to new_path, where "old_path" is a | 109 // This moves a file from old_path to new_path, where "old_path" is a |
119 // plain file. This DCHECKs and returns false if old_path points to a | 110 // plain file. This DCHECKs and returns false if old_path points to a |
120 // directory, and returns true if the function succeeds. | 111 // directory, and returns true if the function succeeds. |
121 virtual bool MoveFile(const Pathname &old_path, const Pathname &new_path) = 0; | 112 virtual bool MoveFile(const Pathname &old_path, const Pathname &new_path) = 0; |
122 | 113 |
123 // Returns true if pathname refers to a directory | 114 // Returns true if pathname refers to a directory |
124 virtual bool IsFolder(const Pathname& pathname) = 0; | 115 virtual bool IsFolder(const Pathname& pathname) = 0; |
125 | 116 |
126 // Returns true if pathname refers to a file | 117 // Returns true if pathname refers to a file |
127 virtual bool IsFile(const Pathname& pathname) = 0; | 118 virtual bool IsFile(const Pathname& pathname) = 0; |
128 | 119 |
129 // Returns true if pathname refers to no filesystem object, every parent | 120 // Returns true if pathname refers to no filesystem object, every parent |
130 // directory either exists, or is also absent. | 121 // directory either exists, or is also absent. |
131 virtual bool IsAbsent(const Pathname& pathname) = 0; | 122 virtual bool IsAbsent(const Pathname& pathname) = 0; |
132 | 123 |
133 // Returns true if pathname represents a temporary location on the system. | |
134 virtual bool IsTemporaryPath(const Pathname& pathname) = 0; | |
135 | |
136 // A folder appropriate for storing temporary files (Contents are | 124 // A folder appropriate for storing temporary files (Contents are |
137 // automatically deleted when the program exits) | 125 // automatically deleted when the program exits) |
138 virtual bool GetTemporaryFolder(Pathname &path, bool create, | 126 virtual bool GetTemporaryFolder(Pathname &path, bool create, |
139 const std::string *append) = 0; | 127 const std::string *append) = 0; |
140 | 128 |
141 virtual std::string TempFilename(const Pathname &dir, | 129 virtual std::string TempFilename(const Pathname &dir, |
142 const std::string &prefix) = 0; | 130 const std::string &prefix) = 0; |
143 | 131 |
144 // Determines the size of the file indicated by path. | 132 // Determines the size of the file indicated by path. |
145 virtual bool GetFileSize(const Pathname& path, size_t* size) = 0; | 133 virtual bool GetFileSize(const Pathname& path, size_t* size) = 0; |
146 | 134 |
147 // Determines a timestamp associated with the file indicated by path. | 135 // Determines a timestamp associated with the file indicated by path. |
148 virtual bool GetFileTime(const Pathname& path, FileTimeType which, | 136 virtual bool GetFileTime(const Pathname& path, FileTimeType which, |
149 time_t* time) = 0; | 137 time_t* time) = 0; |
150 | 138 |
151 // Get a temporary folder that is unique to the current user and application. | |
152 // TODO: Re-evaluate the goals of this function. We probably just need any | |
153 // directory that won't collide with another existing directory, and which | |
154 // will be cleaned up when the program exits. | |
155 virtual bool GetAppTempFolder(Pathname* path) = 0; | |
156 | |
157 // Note: These might go into some shared config section later, but they're | 139 // Note: These might go into some shared config section later, but they're |
158 // used by some methods in this interface, so we're leaving them here for now. | 140 // used by some methods in this interface, so we're leaving them here for now. |
159 void SetOrganizationName(const std::string& organization) { | 141 void SetOrganizationName(const std::string& organization) { |
160 organization_name_ = organization; | 142 organization_name_ = organization; |
161 } | 143 } |
162 void GetOrganizationName(std::string* organization) { | 144 void GetOrganizationName(std::string* organization) { |
163 RTC_DCHECK(organization); | 145 RTC_DCHECK(organization); |
164 *organization = organization_name_; | 146 *organization = organization_name_; |
165 } | 147 } |
166 void SetApplicationName(const std::string& application) { | 148 void SetApplicationName(const std::string& application) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 186 |
205 static FileStream *OpenFile(const Pathname &filename, | 187 static FileStream *OpenFile(const Pathname &filename, |
206 const std::string &mode) { | 188 const std::string &mode) { |
207 return EnsureDefaultFilesystem()->OpenFile(filename, mode); | 189 return EnsureDefaultFilesystem()->OpenFile(filename, mode); |
208 } | 190 } |
209 | 191 |
210 static bool DeleteFile(const Pathname &filename) { | 192 static bool DeleteFile(const Pathname &filename) { |
211 return EnsureDefaultFilesystem()->DeleteFile(filename); | 193 return EnsureDefaultFilesystem()->DeleteFile(filename); |
212 } | 194 } |
213 | 195 |
214 static bool DeleteFolderContents(const Pathname &folder) { | |
215 return EnsureDefaultFilesystem()->DeleteFolderContents(folder); | |
216 } | |
217 | |
218 static bool DeleteFolderAndContents(const Pathname &folder) { | |
219 return EnsureDefaultFilesystem()->DeleteFolderAndContents(folder); | |
220 } | |
221 | |
222 static bool MoveFile(const Pathname &old_path, const Pathname &new_path) { | 196 static bool MoveFile(const Pathname &old_path, const Pathname &new_path) { |
223 return EnsureDefaultFilesystem()->MoveFile(old_path, new_path); | 197 return EnsureDefaultFilesystem()->MoveFile(old_path, new_path); |
224 } | 198 } |
225 | 199 |
226 static bool IsFolder(const Pathname& pathname) { | 200 static bool IsFolder(const Pathname& pathname) { |
227 return EnsureDefaultFilesystem()->IsFolder(pathname); | 201 return EnsureDefaultFilesystem()->IsFolder(pathname); |
228 } | 202 } |
229 | 203 |
230 static bool IsFile(const Pathname &pathname) { | 204 static bool IsFile(const Pathname &pathname) { |
231 return EnsureDefaultFilesystem()->IsFile(pathname); | 205 return EnsureDefaultFilesystem()->IsFile(pathname); |
232 } | 206 } |
233 | 207 |
234 static bool IsAbsent(const Pathname &pathname) { | 208 static bool IsAbsent(const Pathname &pathname) { |
235 return EnsureDefaultFilesystem()->IsAbsent(pathname); | 209 return EnsureDefaultFilesystem()->IsAbsent(pathname); |
236 } | 210 } |
237 | 211 |
238 static bool IsTemporaryPath(const Pathname& pathname) { | |
239 return EnsureDefaultFilesystem()->IsTemporaryPath(pathname); | |
240 } | |
241 | |
242 static bool GetTemporaryFolder(Pathname &path, bool create, | 212 static bool GetTemporaryFolder(Pathname &path, bool create, |
243 const std::string *append) { | 213 const std::string *append) { |
244 return EnsureDefaultFilesystem()->GetTemporaryFolder(path, create, append); | 214 return EnsureDefaultFilesystem()->GetTemporaryFolder(path, create, append); |
245 } | 215 } |
246 | 216 |
247 static std::string TempFilename(const Pathname &dir, | 217 static std::string TempFilename(const Pathname &dir, |
248 const std::string &prefix) { | 218 const std::string &prefix) { |
249 return EnsureDefaultFilesystem()->TempFilename(dir, prefix); | 219 return EnsureDefaultFilesystem()->TempFilename(dir, prefix); |
250 } | 220 } |
251 | 221 |
252 static bool GetFileSize(const Pathname& path, size_t* size) { | 222 static bool GetFileSize(const Pathname& path, size_t* size) { |
253 return EnsureDefaultFilesystem()->GetFileSize(path, size); | 223 return EnsureDefaultFilesystem()->GetFileSize(path, size); |
254 } | 224 } |
255 | 225 |
256 static bool GetFileTime(const Pathname& path, FileTimeType which, | 226 static bool GetFileTime(const Pathname& path, FileTimeType which, |
257 time_t* time) { | 227 time_t* time) { |
258 return EnsureDefaultFilesystem()->GetFileTime(path, which, time); | 228 return EnsureDefaultFilesystem()->GetFileTime(path, which, time); |
259 } | 229 } |
260 | 230 |
261 static bool GetAppTempFolder(Pathname* path) { | |
262 return EnsureDefaultFilesystem()->GetAppTempFolder(path); | |
263 } | |
264 | |
265 static void SetOrganizationName(const std::string& organization) { | 231 static void SetOrganizationName(const std::string& organization) { |
266 EnsureDefaultFilesystem()->SetOrganizationName(organization); | 232 EnsureDefaultFilesystem()->SetOrganizationName(organization); |
267 } | 233 } |
268 | 234 |
269 static void GetOrganizationName(std::string* organization) { | 235 static void GetOrganizationName(std::string* organization) { |
270 EnsureDefaultFilesystem()->GetOrganizationName(organization); | 236 EnsureDefaultFilesystem()->GetOrganizationName(organization); |
271 } | 237 } |
272 | 238 |
273 static void SetApplicationName(const std::string& application) { | 239 static void SetApplicationName(const std::string& application) { |
274 EnsureDefaultFilesystem()->SetApplicationName(application); | 240 EnsureDefaultFilesystem()->SetApplicationName(application); |
275 } | 241 } |
276 | 242 |
277 static void GetApplicationName(std::string* application) { | 243 static void GetApplicationName(std::string* application) { |
278 EnsureDefaultFilesystem()->GetApplicationName(application); | 244 EnsureDefaultFilesystem()->GetApplicationName(application); |
279 } | 245 } |
280 | 246 |
281 private: | 247 private: |
282 static FilesystemInterface* default_filesystem_; | 248 static FilesystemInterface* default_filesystem_; |
283 | 249 |
284 static FilesystemInterface *EnsureDefaultFilesystem(); | 250 static FilesystemInterface *EnsureDefaultFilesystem(); |
285 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Filesystem); | 251 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Filesystem); |
286 }; | 252 }; |
287 | 253 |
288 } // namespace rtc | 254 } // namespace rtc |
289 | 255 |
290 #endif // WEBRTC_BASE_FILEUTILS_H_ | 256 #endif // WEBRTC_BASE_FILEUTILS_H_ |
OLD | NEW |