| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 namespace rtc { | 54 namespace rtc { |
| 55 | 55 |
| 56 UnixFilesystem::UnixFilesystem() {} | 56 UnixFilesystem::UnixFilesystem() {} |
| 57 | 57 |
| 58 UnixFilesystem::~UnixFilesystem() {} | 58 UnixFilesystem::~UnixFilesystem() {} |
| 59 | 59 |
| 60 bool UnixFilesystem::CreateFolder(const Pathname &path, mode_t mode) { | |
| 61 std::string pathname(path.pathname()); | |
| 62 int len = pathname.length(); | |
| 63 if ((len == 0) || (pathname[len - 1] != '/')) | |
| 64 return false; | |
| 65 | |
| 66 struct stat st; | |
| 67 int res = ::stat(pathname.c_str(), &st); | |
| 68 if (res == 0) { | |
| 69 // Something exists at this location, check if it is a directory | |
| 70 return S_ISDIR(st.st_mode) != 0; | |
| 71 } else if (errno != ENOENT) { | |
| 72 // Unexpected error | |
| 73 return false; | |
| 74 } | |
| 75 | |
| 76 // Directory doesn't exist, look up one directory level | |
| 77 do { | |
| 78 --len; | |
| 79 } while ((len > 0) && (pathname[len - 1] != '/')); | |
| 80 | |
| 81 if (!CreateFolder(Pathname(pathname.substr(0, len)), mode)) { | |
| 82 return false; | |
| 83 } | |
| 84 | |
| 85 LOG(LS_INFO) << "Creating folder: " << pathname; | |
| 86 return (0 == ::mkdir(pathname.c_str(), mode)); | |
| 87 } | |
| 88 | |
| 89 bool UnixFilesystem::CreateFolder(const Pathname &path) { | |
| 90 return CreateFolder(path, 0755); | |
| 91 } | |
| 92 | |
| 93 bool UnixFilesystem::DeleteFile(const Pathname &filename) { | 60 bool UnixFilesystem::DeleteFile(const Pathname &filename) { |
| 94 LOG(LS_INFO) << "Deleting file:" << filename.pathname(); | 61 LOG(LS_INFO) << "Deleting file:" << filename.pathname(); |
| 95 | 62 |
| 96 if (!IsFile(filename)) { | 63 if (!IsFile(filename)) { |
| 97 RTC_DCHECK(IsFile(filename)); | 64 RTC_DCHECK(IsFile(filename)); |
| 98 return false; | 65 return false; |
| 99 } | 66 } |
| 100 return ::unlink(filename.pathname().c_str()) == 0; | 67 return ::unlink(filename.pathname().c_str()) == 0; |
| 101 } | 68 } |
| 102 | 69 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 | 133 |
| 167 } // namespace rtc | 134 } // namespace rtc |
| 168 | 135 |
| 169 #if defined(__native_client__) | 136 #if defined(__native_client__) |
| 170 extern "C" int __attribute__((weak)) | 137 extern "C" int __attribute__((weak)) |
| 171 link(const char* oldpath, const char* newpath) { | 138 link(const char* oldpath, const char* newpath) { |
| 172 errno = EACCES; | 139 errno = EACCES; |
| 173 return -1; | 140 return -1; |
| 174 } | 141 } |
| 175 #endif | 142 #endif |
| OLD | NEW |