| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 #include <sys/syslimits.h> | 44 #include <sys/syslimits.h> |
| 45 #endif | 45 #endif |
| 46 | 46 |
| 47 #include "webrtc/rtc_base/arraysize.h" | 47 #include "webrtc/rtc_base/arraysize.h" |
| 48 #include "webrtc/rtc_base/checks.h" | 48 #include "webrtc/rtc_base/checks.h" |
| 49 #include "webrtc/rtc_base/fileutils.h" | 49 #include "webrtc/rtc_base/fileutils.h" |
| 50 #include "webrtc/rtc_base/pathutils.h" | 50 #include "webrtc/rtc_base/pathutils.h" |
| 51 #include "webrtc/rtc_base/stream.h" | 51 #include "webrtc/rtc_base/stream.h" |
| 52 #include "webrtc/rtc_base/stringutils.h" | 52 #include "webrtc/rtc_base/stringutils.h" |
| 53 | 53 |
| 54 #if defined(WEBRTC_MAC) | |
| 55 // Defined in applefilesystem.mm. No header file to discourage use | |
| 56 // elsewhere; other places should use GetApp{Data,Temp}Folder() in | |
| 57 // this file. Don't copy/paste. I mean it. | |
| 58 char* AppleDataDirectory(); | |
| 59 char* AppleTempDirectory(); | |
| 60 void AppleAppName(rtc::Pathname* path); | |
| 61 #endif | |
| 62 | |
| 63 namespace rtc { | 54 namespace rtc { |
| 64 | 55 |
| 65 #if !defined(WEBRTC_ANDROID) && !defined(WEBRTC_MAC) | 56 UnixFilesystem::UnixFilesystem() {} |
| 66 char* UnixFilesystem::app_temp_path_ = nullptr; | |
| 67 #else | |
| 68 char* UnixFilesystem::provided_app_data_folder_ = nullptr; | |
| 69 char* UnixFilesystem::provided_app_temp_folder_ = nullptr; | |
| 70 | |
| 71 void UnixFilesystem::SetAppDataFolder(const std::string& folder) { | |
| 72 delete [] provided_app_data_folder_; | |
| 73 provided_app_data_folder_ = CopyString(folder); | |
| 74 } | |
| 75 | |
| 76 void UnixFilesystem::SetAppTempFolder(const std::string& folder) { | |
| 77 delete [] provided_app_temp_folder_; | |
| 78 provided_app_temp_folder_ = CopyString(folder); | |
| 79 } | |
| 80 #endif | |
| 81 | |
| 82 UnixFilesystem::UnixFilesystem() { | |
| 83 #if defined(WEBRTC_MAC) | |
| 84 if (!provided_app_data_folder_) | |
| 85 provided_app_data_folder_ = AppleDataDirectory(); | |
| 86 if (!provided_app_temp_folder_) | |
| 87 provided_app_temp_folder_ = AppleTempDirectory(); | |
| 88 #endif | |
| 89 } | |
| 90 | 57 |
| 91 UnixFilesystem::~UnixFilesystem() {} | 58 UnixFilesystem::~UnixFilesystem() {} |
| 92 | 59 |
| 93 bool UnixFilesystem::CreateFolder(const Pathname &path, mode_t mode) { | 60 bool UnixFilesystem::CreateFolder(const Pathname &path, mode_t mode) { |
| 94 std::string pathname(path.pathname()); | 61 std::string pathname(path.pathname()); |
| 95 int len = pathname.length(); | 62 int len = pathname.length(); |
| 96 if ((len == 0) || (pathname[len - 1] != '/')) | 63 if ((len == 0) || (pathname[len - 1] != '/')) |
| 97 return false; | 64 return false; |
| 98 | 65 |
| 99 struct stat st; | 66 struct stat st; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 126 bool UnixFilesystem::DeleteFile(const Pathname &filename) { | 93 bool UnixFilesystem::DeleteFile(const Pathname &filename) { |
| 127 LOG(LS_INFO) << "Deleting file:" << filename.pathname(); | 94 LOG(LS_INFO) << "Deleting file:" << filename.pathname(); |
| 128 | 95 |
| 129 if (!IsFile(filename)) { | 96 if (!IsFile(filename)) { |
| 130 RTC_DCHECK(IsFile(filename)); | 97 RTC_DCHECK(IsFile(filename)); |
| 131 return false; | 98 return false; |
| 132 } | 99 } |
| 133 return ::unlink(filename.pathname().c_str()) == 0; | 100 return ::unlink(filename.pathname().c_str()) == 0; |
| 134 } | 101 } |
| 135 | 102 |
| 136 bool UnixFilesystem::GetTemporaryFolder(Pathname &pathname, bool create, | |
| 137 const std::string *append) { | |
| 138 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) | |
| 139 RTC_DCHECK(provided_app_temp_folder_ != nullptr); | |
| 140 pathname.SetPathname(provided_app_temp_folder_, ""); | |
| 141 #else | |
| 142 if (const char* tmpdir = getenv("TMPDIR")) { | |
| 143 pathname.SetPathname(tmpdir, ""); | |
| 144 } else if (const char* tmp = getenv("TMP")) { | |
| 145 pathname.SetPathname(tmp, ""); | |
| 146 } else { | |
| 147 #ifdef P_tmpdir | |
| 148 pathname.SetPathname(P_tmpdir, ""); | |
| 149 #else // !P_tmpdir | |
| 150 pathname.SetPathname("/tmp/", ""); | |
| 151 #endif // !P_tmpdir | |
| 152 } | |
| 153 #endif // defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) | |
| 154 if (append) { | |
| 155 RTC_DCHECK(!append->empty()); | |
| 156 pathname.AppendFolder(*append); | |
| 157 } | |
| 158 return !create || CreateFolder(pathname); | |
| 159 } | |
| 160 | |
| 161 std::string UnixFilesystem::TempFilename(const Pathname &dir, | 103 std::string UnixFilesystem::TempFilename(const Pathname &dir, |
| 162 const std::string &prefix) { | 104 const std::string &prefix) { |
| 163 int len = dir.pathname().size() + prefix.size() + 2 + 6; | 105 int len = dir.pathname().size() + prefix.size() + 2 + 6; |
| 164 char *tempname = new char[len]; | 106 char *tempname = new char[len]; |
| 165 | 107 |
| 166 snprintf(tempname, len, "%s/%sXXXXXX", dir.pathname().c_str(), | 108 snprintf(tempname, len, "%s/%sXXXXXX", dir.pathname().c_str(), |
| 167 prefix.c_str()); | 109 prefix.c_str()); |
| 168 int fd = ::mkstemp(tempname); | 110 int fd = ::mkstemp(tempname); |
| 169 if (fd != -1) | 111 if (fd != -1) |
| 170 ::close(fd); | 112 ::close(fd); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 | 174 |
| 233 } // namespace rtc | 175 } // namespace rtc |
| 234 | 176 |
| 235 #if defined(__native_client__) | 177 #if defined(__native_client__) |
| 236 extern "C" int __attribute__((weak)) | 178 extern "C" int __attribute__((weak)) |
| 237 link(const char* oldpath, const char* newpath) { | 179 link(const char* oldpath, const char* newpath) { |
| 238 errno = EACCES; | 180 errno = EACCES; |
| 239 return -1; | 181 return -1; |
| 240 } | 182 } |
| 241 #endif | 183 #endif |
| OLD | NEW |