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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 // elsewhere; other places should use GetApp{Data,Temp}Folder() in | 56 // elsewhere; other places should use GetApp{Data,Temp}Folder() in |
57 // this file. Don't copy/paste. I mean it. | 57 // this file. Don't copy/paste. I mean it. |
58 char* AppleDataDirectory(); | 58 char* AppleDataDirectory(); |
59 char* AppleTempDirectory(); | 59 char* AppleTempDirectory(); |
60 void AppleAppName(rtc::Pathname* path); | 60 void AppleAppName(rtc::Pathname* path); |
61 #endif | 61 #endif |
62 | 62 |
63 namespace rtc { | 63 namespace rtc { |
64 | 64 |
65 #if !defined(WEBRTC_ANDROID) && !defined(WEBRTC_MAC) | 65 #if !defined(WEBRTC_ANDROID) && !defined(WEBRTC_MAC) |
66 char* UnixFilesystem::app_temp_path_ = NULL; | 66 char* UnixFilesystem::app_temp_path_ = nullptr; |
67 #else | 67 #else |
68 char* UnixFilesystem::provided_app_data_folder_ = NULL; | 68 char* UnixFilesystem::provided_app_data_folder_ = nullptr; |
69 char* UnixFilesystem::provided_app_temp_folder_ = NULL; | 69 char* UnixFilesystem::provided_app_temp_folder_ = nullptr; |
70 | 70 |
71 void UnixFilesystem::SetAppDataFolder(const std::string& folder) { | 71 void UnixFilesystem::SetAppDataFolder(const std::string& folder) { |
72 delete [] provided_app_data_folder_; | 72 delete [] provided_app_data_folder_; |
73 provided_app_data_folder_ = CopyString(folder); | 73 provided_app_data_folder_ = CopyString(folder); |
74 } | 74 } |
75 | 75 |
76 void UnixFilesystem::SetAppTempFolder(const std::string& folder) { | 76 void UnixFilesystem::SetAppTempFolder(const std::string& folder) { |
77 delete [] provided_app_temp_folder_; | 77 delete [] provided_app_temp_folder_; |
78 provided_app_temp_folder_ = CopyString(folder); | 78 provided_app_temp_folder_ = CopyString(folder); |
79 } | 79 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 return (0 == ::mkdir(pathname.c_str(), mode)); | 119 return (0 == ::mkdir(pathname.c_str(), mode)); |
120 } | 120 } |
121 | 121 |
122 bool UnixFilesystem::CreateFolder(const Pathname &path) { | 122 bool UnixFilesystem::CreateFolder(const Pathname &path) { |
123 return CreateFolder(path, 0755); | 123 return CreateFolder(path, 0755); |
124 } | 124 } |
125 | 125 |
126 FileStream *UnixFilesystem::OpenFile(const Pathname &filename, | 126 FileStream *UnixFilesystem::OpenFile(const Pathname &filename, |
127 const std::string &mode) { | 127 const std::string &mode) { |
128 FileStream *fs = new FileStream(); | 128 FileStream *fs = new FileStream(); |
129 if (fs && !fs->Open(filename.pathname().c_str(), mode.c_str(), NULL)) { | 129 if (fs && !fs->Open(filename.pathname().c_str(), mode.c_str(), nullptr)) { |
130 delete fs; | 130 delete fs; |
131 fs = NULL; | 131 fs = nullptr; |
132 } | 132 } |
133 return fs; | 133 return fs; |
134 } | 134 } |
135 | 135 |
136 bool UnixFilesystem::DeleteFile(const Pathname &filename) { | 136 bool UnixFilesystem::DeleteFile(const Pathname &filename) { |
137 LOG(LS_INFO) << "Deleting file:" << filename.pathname(); | 137 LOG(LS_INFO) << "Deleting file:" << filename.pathname(); |
138 | 138 |
139 if (!IsFile(filename)) { | 139 if (!IsFile(filename)) { |
140 RTC_DCHECK(IsFile(filename)); | 140 RTC_DCHECK(IsFile(filename)); |
141 return false; | 141 return false; |
142 } | 142 } |
143 return ::unlink(filename.pathname().c_str()) == 0; | 143 return ::unlink(filename.pathname().c_str()) == 0; |
144 } | 144 } |
145 | 145 |
146 bool UnixFilesystem::DeleteEmptyFolder(const Pathname &folder) { | 146 bool UnixFilesystem::DeleteEmptyFolder(const Pathname &folder) { |
147 LOG(LS_INFO) << "Deleting folder" << folder.pathname(); | 147 LOG(LS_INFO) << "Deleting folder" << folder.pathname(); |
148 | 148 |
149 if (!IsFolder(folder)) { | 149 if (!IsFolder(folder)) { |
150 RTC_DCHECK(IsFolder(folder)); | 150 RTC_DCHECK(IsFolder(folder)); |
151 return false; | 151 return false; |
152 } | 152 } |
153 std::string no_slash(folder.pathname(), 0, folder.pathname().length()-1); | 153 std::string no_slash(folder.pathname(), 0, folder.pathname().length()-1); |
154 return ::rmdir(no_slash.c_str()) == 0; | 154 return ::rmdir(no_slash.c_str()) == 0; |
155 } | 155 } |
156 | 156 |
157 bool UnixFilesystem::GetTemporaryFolder(Pathname &pathname, bool create, | 157 bool UnixFilesystem::GetTemporaryFolder(Pathname &pathname, bool create, |
158 const std::string *append) { | 158 const std::string *append) { |
159 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) | 159 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) |
160 RTC_DCHECK(provided_app_temp_folder_ != NULL); | 160 RTC_DCHECK(provided_app_temp_folder_ != nullptr); |
161 pathname.SetPathname(provided_app_temp_folder_, ""); | 161 pathname.SetPathname(provided_app_temp_folder_, ""); |
162 #else | 162 #else |
163 if (const char* tmpdir = getenv("TMPDIR")) { | 163 if (const char* tmpdir = getenv("TMPDIR")) { |
164 pathname.SetPathname(tmpdir, ""); | 164 pathname.SetPathname(tmpdir, ""); |
165 } else if (const char* tmp = getenv("TMP")) { | 165 } else if (const char* tmp = getenv("TMP")) { |
166 pathname.SetPathname(tmp, ""); | 166 pathname.SetPathname(tmp, ""); |
167 } else { | 167 } else { |
168 #ifdef P_tmpdir | 168 #ifdef P_tmpdir |
169 pathname.SetPathname(P_tmpdir, ""); | 169 pathname.SetPathname(P_tmpdir, ""); |
170 #else // !P_tmpdir | 170 #else // !P_tmpdir |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 StreamInterface *source = OpenFile(old_path, "rb"); | 231 StreamInterface *source = OpenFile(old_path, "rb"); |
232 if (!source) | 232 if (!source) |
233 return false; | 233 return false; |
234 | 234 |
235 StreamInterface *dest = OpenFile(new_path, "wb"); | 235 StreamInterface *dest = OpenFile(new_path, "wb"); |
236 if (!dest) { | 236 if (!dest) { |
237 delete source; | 237 delete source; |
238 return false; | 238 return false; |
239 } | 239 } |
240 | 240 |
241 while (source->Read(buf, sizeof(buf), &len, NULL) == SR_SUCCESS) | 241 while (source->Read(buf, sizeof(buf), &len, nullptr) == SR_SUCCESS) |
242 dest->Write(buf, len, NULL, NULL); | 242 dest->Write(buf, len, nullptr, nullptr); |
243 | 243 |
244 delete source; | 244 delete source; |
245 delete dest; | 245 delete dest; |
246 return true; | 246 return true; |
247 } | 247 } |
248 | 248 |
249 bool UnixFilesystem::IsTemporaryPath(const Pathname& pathname) { | 249 bool UnixFilesystem::IsTemporaryPath(const Pathname& pathname) { |
250 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) | 250 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) |
251 RTC_DCHECK(provided_app_temp_folder_ != NULL); | 251 RTC_DCHECK(provided_app_temp_folder_ != nullptr); |
252 #endif | 252 #endif |
253 | 253 |
254 const char* const kTempPrefixes[] = { | 254 const char* const kTempPrefixes[] = { |
255 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) | 255 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) |
256 provided_app_temp_folder_, | 256 provided_app_temp_folder_, |
257 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) | 257 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) |
258 "/private/tmp/", "/private/var/tmp/", "/private/var/folders/", | 258 "/private/tmp/", "/private/var/tmp/", "/private/var/folders/", |
259 #endif // WEBRTC_MAC && !defined(WEBRTC_IOS) | 259 #endif // WEBRTC_MAC && !defined(WEBRTC_IOS) |
260 #else | 260 #else |
261 "/tmp/", "/var/tmp/", | 261 "/tmp/", "/var/tmp/", |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 bool UnixFilesystem::GetAppDataFolder(Pathname* path, bool per_user) { | 316 bool UnixFilesystem::GetAppDataFolder(Pathname* path, bool per_user) { |
317 // On macOS and iOS, there is no requirement that the path contains the | 317 // On macOS and iOS, there is no requirement that the path contains the |
318 // organization. | 318 // organization. |
319 #if !defined(WEBRTC_MAC) | 319 #if !defined(WEBRTC_MAC) |
320 RTC_DCHECK(!organization_name_.empty()); | 320 RTC_DCHECK(!organization_name_.empty()); |
321 #endif | 321 #endif |
322 RTC_DCHECK(!application_name_.empty()); | 322 RTC_DCHECK(!application_name_.empty()); |
323 | 323 |
324 // First get the base directory for app data. | 324 // First get the base directory for app data. |
325 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) | 325 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) |
326 RTC_DCHECK(provided_app_data_folder_ != NULL); | 326 RTC_DCHECK(provided_app_data_folder_ != nullptr); |
327 path->SetPathname(provided_app_data_folder_, ""); | 327 path->SetPathname(provided_app_data_folder_, ""); |
328 #elif defined(WEBRTC_LINUX) // && !WEBRTC_MAC && !WEBRTC_ANDROID | 328 #elif defined(WEBRTC_LINUX) // && !WEBRTC_MAC && !WEBRTC_ANDROID |
329 if (per_user) { | 329 if (per_user) { |
330 // We follow the recommendations in | 330 // We follow the recommendations in |
331 // http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html | 331 // http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html |
332 // It specifies separate directories for data and config files, but | 332 // It specifies separate directories for data and config files, but |
333 // GetAppDataFolder() does not distinguish. We just return the config dir | 333 // GetAppDataFolder() does not distinguish. We just return the config dir |
334 // path. | 334 // path. |
335 const char* xdg_config_home = getenv("XDG_CONFIG_HOME"); | 335 const char* xdg_config_home = getenv("XDG_CONFIG_HOME"); |
336 if (xdg_config_home) { | 336 if (xdg_config_home) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 if (0 != ::chmod(path->pathname().c_str(), 0700)) { | 383 if (0 != ::chmod(path->pathname().c_str(), 0700)) { |
384 LOG_ERR(LS_ERROR) << "Can't set mode on " << path; | 384 LOG_ERR(LS_ERROR) << "Can't set mode on " << path; |
385 return false; | 385 return false; |
386 } | 386 } |
387 #endif | 387 #endif |
388 return true; | 388 return true; |
389 } | 389 } |
390 | 390 |
391 bool UnixFilesystem::GetAppTempFolder(Pathname* path) { | 391 bool UnixFilesystem::GetAppTempFolder(Pathname* path) { |
392 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) | 392 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) |
393 RTC_DCHECK(provided_app_temp_folder_ != NULL); | 393 RTC_DCHECK(provided_app_temp_folder_ != nullptr); |
394 path->SetPathname(provided_app_temp_folder_); | 394 path->SetPathname(provided_app_temp_folder_); |
395 return true; | 395 return true; |
396 #else | 396 #else |
397 RTC_DCHECK(!application_name_.empty()); | 397 RTC_DCHECK(!application_name_.empty()); |
398 // TODO: Consider whether we are worried about thread safety. | 398 // TODO: Consider whether we are worried about thread safety. |
399 if (app_temp_path_ != NULL && strlen(app_temp_path_) > 0) { | 399 if (app_temp_path_ != nullptr && strlen(app_temp_path_) > 0) { |
400 path->SetPathname(app_temp_path_); | 400 path->SetPathname(app_temp_path_); |
401 return true; | 401 return true; |
402 } | 402 } |
403 | 403 |
404 // Create a random directory as /tmp/<appname>-<pid>-<timestamp> | 404 // Create a random directory as /tmp/<appname>-<pid>-<timestamp> |
405 char buffer[128]; | 405 char buffer[128]; |
406 sprintfn(buffer, arraysize(buffer), "-%d-%d", | 406 sprintfn(buffer, arraysize(buffer), "-%d-%d", |
407 static_cast<int>(getpid()), | 407 static_cast<int>(getpid()), |
408 static_cast<int>(time(0))); | 408 static_cast<int>(time(0))); |
409 std::string folder(application_name_); | 409 std::string folder(application_name_); |
410 folder.append(buffer); | 410 folder.append(buffer); |
411 if (!GetTemporaryFolder(*path, true, &folder)) | 411 if (!GetTemporaryFolder(*path, true, &folder)) |
412 return false; | 412 return false; |
413 | 413 |
414 delete [] app_temp_path_; | 414 delete [] app_temp_path_; |
415 app_temp_path_ = CopyString(path->pathname()); | 415 app_temp_path_ = CopyString(path->pathname()); |
416 // TODO: atexit(DeleteFolderAndContents(app_temp_path_)); | 416 // TODO: atexit(DeleteFolderAndContents(app_temp_path_)); |
417 return true; | 417 return true; |
418 #endif | 418 #endif |
419 } | 419 } |
420 | 420 |
421 bool UnixFilesystem::GetDiskFreeSpace(const Pathname& path, | 421 bool UnixFilesystem::GetDiskFreeSpace(const Pathname& path, |
422 int64_t* freebytes) { | 422 int64_t* freebytes) { |
423 #ifdef __native_client__ | 423 #ifdef __native_client__ |
424 return false; | 424 return false; |
425 #else // __native_client__ | 425 #else // __native_client__ |
426 RTC_DCHECK(NULL != freebytes); | 426 RTC_DCHECK(nullptr != freebytes); |
427 // TODO: Consider making relative paths absolute using cwd. | 427 // TODO: Consider making relative paths absolute using cwd. |
428 // TODO: When popping off a symlink, push back on the components of the | 428 // TODO: When popping off a symlink, push back on the components of the |
429 // symlink, so we don't jump out of the target disk inadvertently. | 429 // symlink, so we don't jump out of the target disk inadvertently. |
430 Pathname existing_path(path.folder(), ""); | 430 Pathname existing_path(path.folder(), ""); |
431 while (!existing_path.folder().empty() && IsAbsent(existing_path)) { | 431 while (!existing_path.folder().empty() && IsAbsent(existing_path)) { |
432 existing_path.SetFolder(existing_path.parent_folder()); | 432 existing_path.SetFolder(existing_path.parent_folder()); |
433 } | 433 } |
434 #if defined(WEBRTC_ANDROID) | 434 #if defined(WEBRTC_ANDROID) |
435 struct statfs vfs; | 435 struct statfs vfs; |
436 memset(&vfs, 0, sizeof(vfs)); | 436 memset(&vfs, 0, sizeof(vfs)); |
(...skipping 13 matching lines...) Expand all Loading... |
450 | 450 |
451 return true; | 451 return true; |
452 #endif // !__native_client__ | 452 #endif // !__native_client__ |
453 } | 453 } |
454 | 454 |
455 char* UnixFilesystem::CopyString(const std::string& str) { | 455 char* UnixFilesystem::CopyString(const std::string& str) { |
456 size_t size = str.length() + 1; | 456 size_t size = str.length() + 1; |
457 | 457 |
458 char* buf = new char[size]; | 458 char* buf = new char[size]; |
459 if (!buf) { | 459 if (!buf) { |
460 return NULL; | 460 return nullptr; |
461 } | 461 } |
462 | 462 |
463 strcpyn(buf, size, str.c_str()); | 463 strcpyn(buf, size, str.c_str()); |
464 return buf; | 464 return buf; |
465 } | 465 } |
466 | 466 |
467 } // namespace rtc | 467 } // namespace rtc |
468 | 468 |
469 #if defined(__native_client__) | 469 #if defined(__native_client__) |
470 extern "C" int __attribute__((weak)) | 470 extern "C" int __attribute__((weak)) |
471 link(const char* oldpath, const char* newpath) { | 471 link(const char* oldpath, const char* newpath) { |
472 errno = EACCES; | 472 errno = EACCES; |
473 return -1; | 473 return -1; |
474 } | 474 } |
475 #endif | 475 #endif |
OLD | NEW |