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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 // Defined in applefilesystem.mm. No header file to discourage use | 54 // Defined in applefilesystem.mm. No header file to discourage use |
55 // elsewhere; other places should use GetApp{Data,Temp}Folder() in | 55 // elsewhere; other places should use GetApp{Data,Temp}Folder() in |
56 // this file. Don't copy/paste. I mean it. | 56 // this file. Don't copy/paste. I mean it. |
57 char* AppleDataDirectory(); | 57 char* AppleDataDirectory(); |
58 char* AppleTempDirectory(); | 58 char* AppleTempDirectory(); |
59 void AppleAppName(rtc::Pathname* path); | 59 void AppleAppName(rtc::Pathname* path); |
60 #endif | 60 #endif |
61 | 61 |
62 namespace rtc { | 62 namespace rtc { |
63 | 63 |
64 #if !defined(WEBRTC_ANDROID) && !defined(WEBRTC_IOS) | 64 #if !defined(WEBRTC_ANDROID) && !defined(WEBRTC_MAC) |
65 char* UnixFilesystem::app_temp_path_ = NULL; | 65 char* UnixFilesystem::app_temp_path_ = NULL; |
66 #else | 66 #else |
67 char* UnixFilesystem::provided_app_data_folder_ = NULL; | 67 char* UnixFilesystem::provided_app_data_folder_ = NULL; |
68 char* UnixFilesystem::provided_app_temp_folder_ = NULL; | 68 char* UnixFilesystem::provided_app_temp_folder_ = NULL; |
69 | 69 |
70 void UnixFilesystem::SetAppDataFolder(const std::string& folder) { | 70 void UnixFilesystem::SetAppDataFolder(const std::string& folder) { |
71 delete [] provided_app_data_folder_; | 71 delete [] provided_app_data_folder_; |
72 provided_app_data_folder_ = CopyString(folder); | 72 provided_app_data_folder_ = CopyString(folder); |
73 } | 73 } |
74 | 74 |
75 void UnixFilesystem::SetAppTempFolder(const std::string& folder) { | 75 void UnixFilesystem::SetAppTempFolder(const std::string& folder) { |
76 delete [] provided_app_temp_folder_; | 76 delete [] provided_app_temp_folder_; |
77 provided_app_temp_folder_ = CopyString(folder); | 77 provided_app_temp_folder_ = CopyString(folder); |
78 } | 78 } |
79 #endif | 79 #endif |
80 | 80 |
81 UnixFilesystem::UnixFilesystem() { | 81 UnixFilesystem::UnixFilesystem() { |
82 #if defined(WEBRTC_IOS) | 82 #if defined(WEBRTC_MAC) |
83 if (!provided_app_data_folder_) | 83 if (!provided_app_data_folder_) |
84 provided_app_data_folder_ = AppleDataDirectory(); | 84 provided_app_data_folder_ = AppleDataDirectory(); |
85 if (!provided_app_temp_folder_) | 85 if (!provided_app_temp_folder_) |
86 provided_app_temp_folder_ = AppleTempDirectory(); | 86 provided_app_temp_folder_ = AppleTempDirectory(); |
87 #endif | 87 #endif |
88 } | 88 } |
89 | 89 |
90 UnixFilesystem::~UnixFilesystem() {} | 90 UnixFilesystem::~UnixFilesystem() {} |
91 | 91 |
92 bool UnixFilesystem::CreateFolder(const Pathname &path, mode_t mode) { | 92 bool UnixFilesystem::CreateFolder(const Pathname &path, mode_t mode) { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 if (!IsFolder(folder)) { | 164 if (!IsFolder(folder)) { |
165 ASSERT(IsFolder(folder)); | 165 ASSERT(IsFolder(folder)); |
166 return false; | 166 return false; |
167 } | 167 } |
168 std::string no_slash(folder.pathname(), 0, folder.pathname().length()-1); | 168 std::string no_slash(folder.pathname(), 0, folder.pathname().length()-1); |
169 return ::rmdir(no_slash.c_str()) == 0; | 169 return ::rmdir(no_slash.c_str()) == 0; |
170 } | 170 } |
171 | 171 |
172 bool UnixFilesystem::GetTemporaryFolder(Pathname &pathname, bool create, | 172 bool UnixFilesystem::GetTemporaryFolder(Pathname &pathname, bool create, |
173 const std::string *append) { | 173 const std::string *append) { |
174 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) | 174 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) |
175 ASSERT(provided_app_temp_folder_ != NULL); | 175 ASSERT(provided_app_temp_folder_ != NULL); |
176 pathname.SetPathname(provided_app_temp_folder_, ""); | 176 pathname.SetPathname(provided_app_temp_folder_, ""); |
177 #else | 177 #else |
178 if (const char* tmpdir = getenv("TMPDIR")) { | 178 if (const char* tmpdir = getenv("TMPDIR")) { |
179 pathname.SetPathname(tmpdir, ""); | 179 pathname.SetPathname(tmpdir, ""); |
180 } else if (const char* tmp = getenv("TMP")) { | 180 } else if (const char* tmp = getenv("TMP")) { |
181 pathname.SetPathname(tmp, ""); | 181 pathname.SetPathname(tmp, ""); |
182 } else { | 182 } else { |
183 #ifdef P_tmpdir | 183 #ifdef P_tmpdir |
184 pathname.SetPathname(P_tmpdir, ""); | 184 pathname.SetPathname(P_tmpdir, ""); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 | 274 |
275 while (source->Read(buf, sizeof(buf), &len, NULL) == SR_SUCCESS) | 275 while (source->Read(buf, sizeof(buf), &len, NULL) == SR_SUCCESS) |
276 dest->Write(buf, len, NULL, NULL); | 276 dest->Write(buf, len, NULL, NULL); |
277 | 277 |
278 delete source; | 278 delete source; |
279 delete dest; | 279 delete dest; |
280 return true; | 280 return true; |
281 } | 281 } |
282 | 282 |
283 bool UnixFilesystem::IsTemporaryPath(const Pathname& pathname) { | 283 bool UnixFilesystem::IsTemporaryPath(const Pathname& pathname) { |
284 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) | 284 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) |
285 ASSERT(provided_app_temp_folder_ != NULL); | 285 ASSERT(provided_app_temp_folder_ != NULL); |
286 #endif | 286 #endif |
287 | 287 |
288 const char* const kTempPrefixes[] = { | 288 const char* const kTempPrefixes[] = { |
289 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) | 289 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) |
290 provided_app_temp_folder_, | 290 provided_app_temp_folder_, |
291 #else | |
292 "/tmp/", "/var/tmp/", | |
293 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) | 291 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) |
294 "/private/tmp/", "/private/var/tmp/", "/private/var/folders/", | 292 "/private/tmp/", "/private/var/tmp/", "/private/var/folders/", |
295 #endif // WEBRTC_MAC && !defined(WEBRTC_IOS) | 293 #endif // WEBRTC_MAC && !defined(WEBRTC_IOS) |
| 294 #else |
| 295 "/tmp/", "/var/tmp/", |
296 #endif // WEBRTC_ANDROID || WEBRTC_IOS | 296 #endif // WEBRTC_ANDROID || WEBRTC_IOS |
297 }; | 297 }; |
298 for (size_t i = 0; i < arraysize(kTempPrefixes); ++i) { | 298 for (size_t i = 0; i < arraysize(kTempPrefixes); ++i) { |
299 if (0 == strncmp(pathname.pathname().c_str(), kTempPrefixes[i], | 299 if (0 == strncmp(pathname.pathname().c_str(), kTempPrefixes[i], |
300 strlen(kTempPrefixes[i]))) | 300 strlen(kTempPrefixes[i]))) |
301 return true; | 301 return true; |
302 } | 302 } |
303 return false; | 303 return false; |
304 } | 304 } |
305 | 305 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 ssize_t len = readlink("/proc/self/exe", buffer, arraysize(buffer) - 1); | 358 ssize_t len = readlink("/proc/self/exe", buffer, arraysize(buffer) - 1); |
359 if ((len <= 0) || (len == PATH_MAX + 1)) | 359 if ((len <= 0) || (len == PATH_MAX + 1)) |
360 return false; | 360 return false; |
361 buffer[len] = '\0'; | 361 buffer[len] = '\0'; |
362 path->SetPathname(buffer); | 362 path->SetPathname(buffer); |
363 return true; | 363 return true; |
364 #endif // WEBRTC_MAC && !defined(WEBRTC_IOS) | 364 #endif // WEBRTC_MAC && !defined(WEBRTC_IOS) |
365 } | 365 } |
366 | 366 |
367 bool UnixFilesystem::GetAppDataFolder(Pathname* path, bool per_user) { | 367 bool UnixFilesystem::GetAppDataFolder(Pathname* path, bool per_user) { |
| 368 // On macOS and iOS, there is no requirement that the path contains the |
| 369 // organization. |
| 370 #if !defined(WEBRTC_MAC) |
368 ASSERT(!organization_name_.empty()); | 371 ASSERT(!organization_name_.empty()); |
| 372 #endif |
369 ASSERT(!application_name_.empty()); | 373 ASSERT(!application_name_.empty()); |
370 | 374 |
371 // First get the base directory for app data. | 375 // First get the base directory for app data. |
372 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) | 376 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) |
373 if (per_user) { | |
374 // Use ~/Library/Application Support/<orgname>/<appname>/ | |
375 FSRef fr; | |
376 if (0 != FSFindFolder(kUserDomain, kApplicationSupportFolderType, | |
377 kCreateFolder, &fr)) | |
378 return false; | |
379 unsigned char buffer[NAME_MAX+1]; | |
380 if (0 != FSRefMakePath(&fr, buffer, arraysize(buffer))) | |
381 return false; | |
382 path->SetPathname(reinterpret_cast<char*>(buffer), ""); | |
383 } else { | |
384 // TODO | |
385 return false; | |
386 } | |
387 #elif defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) // && !WEBRTC_MAC || WEBRT
C_IOS | |
388 ASSERT(provided_app_data_folder_ != NULL); | 377 ASSERT(provided_app_data_folder_ != NULL); |
389 path->SetPathname(provided_app_data_folder_, ""); | 378 path->SetPathname(provided_app_data_folder_, ""); |
390 #elif defined(WEBRTC_LINUX) && !defined(WEBRTC_ANDROID) // && !WEBRTC_MAC && !W
EBRTC_IOS && !WEBRTC_ANDROID | 379 #elif defined(WEBRTC_LINUX) // && !WEBRTC_MAC && !WEBRTC_ANDROID |
391 if (per_user) { | 380 if (per_user) { |
392 // We follow the recommendations in | 381 // We follow the recommendations in |
393 // http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html | 382 // http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html |
394 // It specifies separate directories for data and config files, but | 383 // It specifies separate directories for data and config files, but |
395 // GetAppDataFolder() does not distinguish. We just return the config dir | 384 // GetAppDataFolder() does not distinguish. We just return the config dir |
396 // path. | 385 // path. |
397 const char* xdg_config_home = getenv("XDG_CONFIG_HOME"); | 386 const char* xdg_config_home = getenv("XDG_CONFIG_HOME"); |
398 if (xdg_config_home) { | 387 if (xdg_config_home) { |
399 path->SetPathname(xdg_config_home, ""); | 388 path->SetPathname(xdg_config_home, ""); |
400 } else { | 389 } else { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 // avoids both issues since it will fail if the path is not owned by us. | 433 // avoids both issues since it will fail if the path is not owned by us. |
445 if (0 != ::chmod(path->pathname().c_str(), 0700)) { | 434 if (0 != ::chmod(path->pathname().c_str(), 0700)) { |
446 LOG_ERR(LS_ERROR) << "Can't set mode on " << path; | 435 LOG_ERR(LS_ERROR) << "Can't set mode on " << path; |
447 return false; | 436 return false; |
448 } | 437 } |
449 #endif | 438 #endif |
450 return true; | 439 return true; |
451 } | 440 } |
452 | 441 |
453 bool UnixFilesystem::GetAppTempFolder(Pathname* path) { | 442 bool UnixFilesystem::GetAppTempFolder(Pathname* path) { |
454 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) | 443 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) |
455 ASSERT(provided_app_temp_folder_ != NULL); | 444 ASSERT(provided_app_temp_folder_ != NULL); |
456 path->SetPathname(provided_app_temp_folder_); | 445 path->SetPathname(provided_app_temp_folder_); |
457 return true; | 446 return true; |
458 #else | 447 #else |
459 ASSERT(!application_name_.empty()); | 448 ASSERT(!application_name_.empty()); |
460 // TODO: Consider whether we are worried about thread safety. | 449 // TODO: Consider whether we are worried about thread safety. |
461 if (app_temp_path_ != NULL && strlen(app_temp_path_) > 0) { | 450 if (app_temp_path_ != NULL && strlen(app_temp_path_) > 0) { |
462 path->SetPathname(app_temp_path_); | 451 path->SetPathname(app_temp_path_); |
463 return true; | 452 return true; |
464 } | 453 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 | 531 |
543 } // namespace rtc | 532 } // namespace rtc |
544 | 533 |
545 #if defined(__native_client__) | 534 #if defined(__native_client__) |
546 extern "C" int __attribute__((weak)) | 535 extern "C" int __attribute__((weak)) |
547 link(const char* oldpath, const char* newpath) { | 536 link(const char* oldpath, const char* newpath) { |
548 errno = EACCES; | 537 errno = EACCES; |
549 return -1; | 538 return -1; |
550 } | 539 } |
551 #endif | 540 #endif |
OLD | NEW |