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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 #if defined(WEBRTC_WIN) | 67 #if defined(WEBRTC_WIN) |
68 WIN32_FIND_DATA data_; | 68 WIN32_FIND_DATA data_; |
69 HANDLE handle_; | 69 HANDLE handle_; |
70 #else | 70 #else |
71 DIR *dir_; | 71 DIR *dir_; |
72 struct dirent *dirent_; | 72 struct dirent *dirent_; |
73 struct stat stat_; | 73 struct stat stat_; |
74 #endif | 74 #endif |
75 }; | 75 }; |
76 | 76 |
77 enum FileTimeType { FTT_CREATED, FTT_MODIFIED, FTT_ACCESSED }; | |
78 | |
79 class FilesystemInterface { | 77 class FilesystemInterface { |
80 public: | 78 public: |
81 virtual ~FilesystemInterface() {} | 79 virtual ~FilesystemInterface() {} |
82 | 80 |
83 // This will attempt to delete the path located at filename. | 81 // This will attempt to delete the path located at filename. |
84 // It DCHECKs and returns false if the path points to a folder or a | 82 // It DCHECKs and returns false if the path points to a folder or a |
85 // non-existent file. | 83 // non-existent file. |
86 virtual bool DeleteFile(const Pathname &filename) = 0; | 84 virtual bool DeleteFile(const Pathname &filename) = 0; |
87 | 85 |
88 // Creates a directory. This will call itself recursively to create /foo/bar | 86 // Creates a directory. This will call itself recursively to create /foo/bar |
(...skipping 18 matching lines...) Expand all Loading... |
107 // A folder appropriate for storing temporary files (Contents are | 105 // A folder appropriate for storing temporary files (Contents are |
108 // automatically deleted when the program exits) | 106 // automatically deleted when the program exits) |
109 virtual bool GetTemporaryFolder(Pathname &path, bool create, | 107 virtual bool GetTemporaryFolder(Pathname &path, bool create, |
110 const std::string *append) = 0; | 108 const std::string *append) = 0; |
111 | 109 |
112 virtual std::string TempFilename(const Pathname &dir, | 110 virtual std::string TempFilename(const Pathname &dir, |
113 const std::string &prefix) = 0; | 111 const std::string &prefix) = 0; |
114 | 112 |
115 // Determines the size of the file indicated by path. | 113 // Determines the size of the file indicated by path. |
116 virtual bool GetFileSize(const Pathname& path, size_t* size) = 0; | 114 virtual bool GetFileSize(const Pathname& path, size_t* size) = 0; |
117 | |
118 // Determines a timestamp associated with the file indicated by path. | |
119 virtual bool GetFileTime(const Pathname& path, FileTimeType which, | |
120 time_t* time) = 0; | |
121 }; | 115 }; |
122 | 116 |
123 class Filesystem { | 117 class Filesystem { |
124 public: | 118 public: |
125 static FilesystemInterface *default_filesystem() { | 119 static FilesystemInterface *default_filesystem() { |
126 RTC_DCHECK(default_filesystem_); | 120 RTC_DCHECK(default_filesystem_); |
127 return default_filesystem_; | 121 return default_filesystem_; |
128 } | 122 } |
129 | 123 |
130 static void set_default_filesystem(FilesystemInterface *filesystem) { | 124 static void set_default_filesystem(FilesystemInterface *filesystem) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 | 163 |
170 static std::string TempFilename(const Pathname &dir, | 164 static std::string TempFilename(const Pathname &dir, |
171 const std::string &prefix) { | 165 const std::string &prefix) { |
172 return EnsureDefaultFilesystem()->TempFilename(dir, prefix); | 166 return EnsureDefaultFilesystem()->TempFilename(dir, prefix); |
173 } | 167 } |
174 | 168 |
175 static bool GetFileSize(const Pathname& path, size_t* size) { | 169 static bool GetFileSize(const Pathname& path, size_t* size) { |
176 return EnsureDefaultFilesystem()->GetFileSize(path, size); | 170 return EnsureDefaultFilesystem()->GetFileSize(path, size); |
177 } | 171 } |
178 | 172 |
179 static bool GetFileTime(const Pathname& path, FileTimeType which, | |
180 time_t* time) { | |
181 return EnsureDefaultFilesystem()->GetFileTime(path, which, time); | |
182 } | |
183 | |
184 private: | 173 private: |
185 static FilesystemInterface* default_filesystem_; | 174 static FilesystemInterface* default_filesystem_; |
186 | 175 |
187 static FilesystemInterface *EnsureDefaultFilesystem(); | 176 static FilesystemInterface *EnsureDefaultFilesystem(); |
188 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Filesystem); | 177 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Filesystem); |
189 }; | 178 }; |
190 | 179 |
191 } // namespace rtc | 180 } // namespace rtc |
192 | 181 |
193 #endif // WEBRTC_BASE_FILEUTILS_H_ | 182 #endif // WEBRTC_BASE_FILEUTILS_H_ |
OLD | NEW |