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 |
11 #ifndef WEBRTC_BASE_FILEUTILS_H_ | 11 #ifndef WEBRTC_BASE_FILEUTILS_H_ |
12 #define WEBRTC_BASE_FILEUTILS_H_ | 12 #define WEBRTC_BASE_FILEUTILS_H_ |
13 | 13 |
14 #include <string> | 14 #include <string> |
15 | 15 |
16 #if !defined(WEBRTC_WIN) | 16 #if !defined(WEBRTC_WIN) |
17 #include <dirent.h> | 17 #include <dirent.h> |
18 #include <stdio.h> | 18 #include <stdio.h> |
19 #include <sys/stat.h> | 19 #include <sys/stat.h> |
20 #include <sys/types.h> | 20 #include <sys/types.h> |
21 #include <unistd.h> | 21 #include <unistd.h> |
22 #endif | 22 #endif |
23 | 23 |
24 #include "webrtc/base/checks.h" | 24 #include "webrtc/base/checks.h" |
25 #include "webrtc/base/constructormagic.h" | 25 #include "webrtc/base/constructormagic.h" |
26 #include "webrtc/base/platform_file.h" | 26 #include "webrtc/base/platform_file.h" |
27 | 27 |
28 namespace rtc { | 28 namespace rtc { |
29 | 29 |
30 class FileStream; | |
31 class Pathname; | 30 class Pathname; |
32 | 31 |
33 ////////////////////////// | |
34 // Directory Iterator // | |
35 ////////////////////////// | |
36 | |
37 // A DirectoryIterator is created with a given directory. It originally points | |
38 // to the first file in the directory, and can be advanecd with Next(). This | |
39 // allows you to get information about each file. | |
40 | |
41 class DirectoryIterator { | |
42 friend class Filesystem; | |
43 public: | |
44 // Constructor | |
45 DirectoryIterator(); | |
46 // Destructor | |
47 virtual ~DirectoryIterator(); | |
48 | |
49 // Starts traversing a directory | |
50 // dir is the directory to traverse | |
51 // returns true if the directory exists and is valid | |
52 // The iterator will point to the first entry in the directory | |
53 virtual bool Iterate(const Pathname &path); | |
54 | |
55 // Advances to the next file | |
56 // returns true if there were more files in the directory. | |
57 virtual bool Next(); | |
58 | |
59 // returns true if the file currently pointed to is a directory | |
60 virtual bool IsDirectory() const; | |
61 | |
62 // returns the name of the file currently pointed to | |
63 virtual std::string Name() const; | |
64 | |
65 private: | |
66 std::string directory_; | |
67 #if defined(WEBRTC_WIN) | |
68 WIN32_FIND_DATA data_; | |
69 HANDLE handle_; | |
70 #else | |
71 DIR *dir_; | |
72 struct dirent *dirent_; | |
73 struct stat stat_; | |
74 #endif | |
75 }; | |
76 | |
77 class FilesystemInterface { | 32 class FilesystemInterface { |
78 public: | 33 public: |
79 virtual ~FilesystemInterface() {} | 34 virtual ~FilesystemInterface() {} |
80 | 35 |
81 // This will attempt to delete the path located at filename. | 36 // This will attempt to delete the path located at filename. |
82 // It DCHECKs and returns false if the path points to a folder or a | 37 // It DCHECKs and returns false if the path points to a folder or a |
83 // non-existent file. | 38 // non-existent file. |
84 virtual bool DeleteFile(const Pathname &filename) = 0; | 39 virtual bool DeleteFile(const Pathname &filename) = 0; |
85 | 40 |
86 // Creates a directory. This will call itself recursively to create /foo/bar | 41 // Creates a directory. This will call itself recursively to create /foo/bar |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 private: | 128 private: |
174 static FilesystemInterface* default_filesystem_; | 129 static FilesystemInterface* default_filesystem_; |
175 | 130 |
176 static FilesystemInterface *EnsureDefaultFilesystem(); | 131 static FilesystemInterface *EnsureDefaultFilesystem(); |
177 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Filesystem); | 132 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Filesystem); |
178 }; | 133 }; |
179 | 134 |
180 } // namespace rtc | 135 } // namespace rtc |
181 | 136 |
182 #endif // WEBRTC_BASE_FILEUTILS_H_ | 137 #endif // WEBRTC_BASE_FILEUTILS_H_ |
OLD | NEW |