Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: webrtc/base/unixfilesystem.cc

Issue 2747373003: Delete FilesystemInterface::CopyFile. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/base/unixfilesystem.h ('k') | webrtc/base/win32filesystem.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 197
198 bool UnixFilesystem::MoveFile(const Pathname &old_path, 198 bool UnixFilesystem::MoveFile(const Pathname &old_path,
199 const Pathname &new_path) { 199 const Pathname &new_path) {
200 if (!IsFile(old_path)) { 200 if (!IsFile(old_path)) {
201 RTC_DCHECK(IsFile(old_path)); 201 RTC_DCHECK(IsFile(old_path));
202 return false; 202 return false;
203 } 203 }
204 LOG(LS_VERBOSE) << "Moving " << old_path.pathname() 204 LOG(LS_VERBOSE) << "Moving " << old_path.pathname()
205 << " to " << new_path.pathname(); 205 << " to " << new_path.pathname();
206 if (rename(old_path.pathname().c_str(), new_path.pathname().c_str()) != 0) { 206 if (rename(old_path.pathname().c_str(), new_path.pathname().c_str()) != 0) {
207 if (errno != EXDEV) 207 return false;
208 return false;
209 if (!CopyFile(old_path, new_path))
210 return false;
211 if (!DeleteFile(old_path))
212 return false;
213 } 208 }
214 return true; 209 return true;
215 } 210 }
216 211
217 bool UnixFilesystem::IsFolder(const Pathname &path) { 212 bool UnixFilesystem::IsFolder(const Pathname &path) {
218 struct stat st; 213 struct stat st;
219 if (stat(path.pathname().c_str(), &st) < 0) 214 if (stat(path.pathname().c_str(), &st) < 0)
220 return false; 215 return false;
221 return S_ISDIR(st.st_mode); 216 return S_ISDIR(st.st_mode);
222 } 217 }
223 218
224 bool UnixFilesystem::CopyFile(const Pathname &old_path,
225 const Pathname &new_path) {
226 LOG(LS_VERBOSE) << "Copying " << old_path.pathname()
227 << " to " << new_path.pathname();
228 char buf[256];
229 size_t len;
230
231 StreamInterface *source = OpenFile(old_path, "rb");
232 if (!source)
233 return false;
234
235 StreamInterface *dest = OpenFile(new_path, "wb");
236 if (!dest) {
237 delete source;
238 return false;
239 }
240
241 while (source->Read(buf, sizeof(buf), &len, nullptr) == SR_SUCCESS)
242 dest->Write(buf, len, nullptr, nullptr);
243
244 delete source;
245 delete dest;
246 return true;
247 }
248
249 bool UnixFilesystem::IsTemporaryPath(const Pathname& pathname) { 219 bool UnixFilesystem::IsTemporaryPath(const Pathname& pathname) {
250 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) 220 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC)
251 RTC_DCHECK(provided_app_temp_folder_ != nullptr); 221 RTC_DCHECK(provided_app_temp_folder_ != nullptr);
252 #endif 222 #endif
253 223
254 const char* const kTempPrefixes[] = { 224 const char* const kTempPrefixes[] = {
255 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) 225 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC)
256 provided_app_temp_folder_, 226 provided_app_temp_folder_,
257 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) 227 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
258 "/private/tmp/", "/private/var/tmp/", "/private/var/folders/", 228 "/private/tmp/", "/private/var/tmp/", "/private/var/folders/",
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 327
358 } // namespace rtc 328 } // namespace rtc
359 329
360 #if defined(__native_client__) 330 #if defined(__native_client__)
361 extern "C" int __attribute__((weak)) 331 extern "C" int __attribute__((weak))
362 link(const char* oldpath, const char* newpath) { 332 link(const char* oldpath, const char* newpath) {
363 errno = EACCES; 333 errno = EACCES;
364 return -1; 334 return -1;
365 } 335 }
366 #endif 336 #endif
OLDNEW
« no previous file with comments | « webrtc/base/unixfilesystem.h ('k') | webrtc/base/win32filesystem.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698