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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 return true; | 209 return true; |
210 } | 210 } |
211 | 211 |
212 bool UnixFilesystem::IsFolder(const Pathname &path) { | 212 bool UnixFilesystem::IsFolder(const Pathname &path) { |
213 struct stat st; | 213 struct stat st; |
214 if (stat(path.pathname().c_str(), &st) < 0) | 214 if (stat(path.pathname().c_str(), &st) < 0) |
215 return false; | 215 return false; |
216 return S_ISDIR(st.st_mode); | 216 return S_ISDIR(st.st_mode); |
217 } | 217 } |
218 | 218 |
219 bool UnixFilesystem::IsTemporaryPath(const Pathname& pathname) { | |
220 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) | |
221 RTC_DCHECK(provided_app_temp_folder_ != nullptr); | |
222 #endif | |
223 | |
224 const char* const kTempPrefixes[] = { | |
225 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) | |
226 provided_app_temp_folder_, | |
227 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) | |
228 "/private/tmp/", "/private/var/tmp/", "/private/var/folders/", | |
229 #endif // WEBRTC_MAC && !defined(WEBRTC_IOS) | |
230 #else | |
231 "/tmp/", "/var/tmp/", | |
232 #endif // WEBRTC_ANDROID || WEBRTC_IOS | |
233 }; | |
234 for (size_t i = 0; i < arraysize(kTempPrefixes); ++i) { | |
235 if (0 == strncmp(pathname.pathname().c_str(), kTempPrefixes[i], | |
236 strlen(kTempPrefixes[i]))) | |
237 return true; | |
238 } | |
239 return false; | |
240 } | |
241 | |
242 bool UnixFilesystem::IsFile(const Pathname& pathname) { | 219 bool UnixFilesystem::IsFile(const Pathname& pathname) { |
243 struct stat st; | 220 struct stat st; |
244 int res = ::stat(pathname.pathname().c_str(), &st); | 221 int res = ::stat(pathname.pathname().c_str(), &st); |
245 // Treat symlinks, named pipes, etc. all as files. | 222 // Treat symlinks, named pipes, etc. all as files. |
246 return res == 0 && !S_ISDIR(st.st_mode); | 223 return res == 0 && !S_ISDIR(st.st_mode); |
247 } | 224 } |
248 | 225 |
249 bool UnixFilesystem::IsAbsent(const Pathname& pathname) { | 226 bool UnixFilesystem::IsAbsent(const Pathname& pathname) { |
250 struct stat st; | 227 struct stat st; |
251 int res = ::stat(pathname.pathname().c_str(), &st); | 228 int res = ::stat(pathname.pathname().c_str(), &st); |
(...skipping 24 matching lines...) Expand all Loading... |
276 break; | 253 break; |
277 case FTT_ACCESSED: | 254 case FTT_ACCESSED: |
278 *time = st.st_atime; | 255 *time = st.st_atime; |
279 break; | 256 break; |
280 default: | 257 default: |
281 return false; | 258 return false; |
282 } | 259 } |
283 return true; | 260 return true; |
284 } | 261 } |
285 | 262 |
286 bool UnixFilesystem::GetAppTempFolder(Pathname* path) { | |
287 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) | |
288 RTC_DCHECK(provided_app_temp_folder_ != nullptr); | |
289 path->SetPathname(provided_app_temp_folder_); | |
290 return true; | |
291 #else | |
292 RTC_DCHECK(!application_name_.empty()); | |
293 // TODO: Consider whether we are worried about thread safety. | |
294 if (app_temp_path_ != nullptr && strlen(app_temp_path_) > 0) { | |
295 path->SetPathname(app_temp_path_); | |
296 return true; | |
297 } | |
298 | |
299 // Create a random directory as /tmp/<appname>-<pid>-<timestamp> | |
300 char buffer[128]; | |
301 sprintfn(buffer, arraysize(buffer), "-%d-%d", | |
302 static_cast<int>(getpid()), | |
303 static_cast<int>(time(0))); | |
304 std::string folder(application_name_); | |
305 folder.append(buffer); | |
306 if (!GetTemporaryFolder(*path, true, &folder)) | |
307 return false; | |
308 | |
309 delete [] app_temp_path_; | |
310 app_temp_path_ = CopyString(path->pathname()); | |
311 // TODO: atexit(DeleteFolderAndContents(app_temp_path_)); | |
312 return true; | |
313 #endif | |
314 } | |
315 | |
316 char* UnixFilesystem::CopyString(const std::string& str) { | 263 char* UnixFilesystem::CopyString(const std::string& str) { |
317 size_t size = str.length() + 1; | 264 size_t size = str.length() + 1; |
318 | 265 |
319 char* buf = new char[size]; | 266 char* buf = new char[size]; |
320 if (!buf) { | 267 if (!buf) { |
321 return nullptr; | 268 return nullptr; |
322 } | 269 } |
323 | 270 |
324 strcpyn(buf, size, str.c_str()); | 271 strcpyn(buf, size, str.c_str()); |
325 return buf; | 272 return buf; |
326 } | 273 } |
327 | 274 |
328 } // namespace rtc | 275 } // namespace rtc |
329 | 276 |
330 #if defined(__native_client__) | 277 #if defined(__native_client__) |
331 extern "C" int __attribute__((weak)) | 278 extern "C" int __attribute__((weak)) |
332 link(const char* oldpath, const char* newpath) { | 279 link(const char* oldpath, const char* newpath) { |
333 errno = EACCES; | 280 errno = EACCES; |
334 return -1; | 281 return -1; |
335 } | 282 } |
336 #endif | 283 #endif |
OLD | NEW |