From 7b3ce5b87239c50bf6a3f1a36099c32176bbe45e Mon Sep 17 00:00:00 2001 From: nisse Date: Thu, 23 Mar 2017 10:54:16 -0700 Subject: [PATCH] Delete FilesystemInterface::CopyFile. Only use of this method was to implement the cross-device case of MoveFile on unix systems. In turn, only use of the MoveFile method is in FileRotatingStream::RotateFiles. Since file rotation should never involve any copying of log data, the MoveFile fallback to copying can be deleted. BUG=webrtc:6424 Review-Url: https://codereview.webrtc.org/2747373003 Cr-Commit-Position: refs/heads/master@{#17364} --- webrtc/base/fileutils.h | 11 ----------- webrtc/base/unixfilesystem.cc | 32 +------------------------------- webrtc/base/unixfilesystem.h | 5 ----- webrtc/base/win32filesystem.cc | 6 ------ webrtc/base/win32filesystem.h | 4 ---- 5 files changed, 1 insertion(+), 57 deletions(-) diff --git a/webrtc/base/fileutils.h b/webrtc/base/fileutils.h index 8f6ec521b2..9847a7b237 100644 --- a/webrtc/base/fileutils.h +++ b/webrtc/base/fileutils.h @@ -118,15 +118,8 @@ class FilesystemInterface { // This moves a file from old_path to new_path, where "old_path" is a // plain file. This DCHECKs and returns false if old_path points to a // directory, and returns true if the function succeeds. - // If the new path is on a different volume than the old path, this function - // will attempt to copy and, if that succeeds, delete the old path. virtual bool MoveFile(const Pathname &old_path, const Pathname &new_path) = 0; - // This copies a file from old_path to new_path. This method DCHECKs and - // returns false if old_path is a folder, and returns true if the copy - // succeeds. - virtual bool CopyFile(const Pathname &old_path, const Pathname &new_path) = 0; - // Returns true if pathname refers to a directory virtual bool IsFolder(const Pathname& pathname) = 0; @@ -230,10 +223,6 @@ class Filesystem { return EnsureDefaultFilesystem()->MoveFile(old_path, new_path); } - static bool CopyFile(const Pathname &old_path, const Pathname &new_path) { - return EnsureDefaultFilesystem()->CopyFile(old_path, new_path); - } - static bool IsFolder(const Pathname& pathname) { return EnsureDefaultFilesystem()->IsFolder(pathname); } diff --git a/webrtc/base/unixfilesystem.cc b/webrtc/base/unixfilesystem.cc index d0da709810..557c478774 100644 --- a/webrtc/base/unixfilesystem.cc +++ b/webrtc/base/unixfilesystem.cc @@ -204,12 +204,7 @@ bool UnixFilesystem::MoveFile(const Pathname &old_path, LOG(LS_VERBOSE) << "Moving " << old_path.pathname() << " to " << new_path.pathname(); if (rename(old_path.pathname().c_str(), new_path.pathname().c_str()) != 0) { - if (errno != EXDEV) - return false; - if (!CopyFile(old_path, new_path)) - return false; - if (!DeleteFile(old_path)) - return false; + return false; } return true; } @@ -221,31 +216,6 @@ bool UnixFilesystem::IsFolder(const Pathname &path) { return S_ISDIR(st.st_mode); } -bool UnixFilesystem::CopyFile(const Pathname &old_path, - const Pathname &new_path) { - LOG(LS_VERBOSE) << "Copying " << old_path.pathname() - << " to " << new_path.pathname(); - char buf[256]; - size_t len; - - StreamInterface *source = OpenFile(old_path, "rb"); - if (!source) - return false; - - StreamInterface *dest = OpenFile(new_path, "wb"); - if (!dest) { - delete source; - return false; - } - - while (source->Read(buf, sizeof(buf), &len, nullptr) == SR_SUCCESS) - dest->Write(buf, len, nullptr, nullptr); - - delete source; - delete dest; - return true; -} - bool UnixFilesystem::IsTemporaryPath(const Pathname& pathname) { #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) RTC_DCHECK(provided_app_temp_folder_ != nullptr); diff --git a/webrtc/base/unixfilesystem.h b/webrtc/base/unixfilesystem.h index 6f90959101..84202e3250 100644 --- a/webrtc/base/unixfilesystem.h +++ b/webrtc/base/unixfilesystem.h @@ -62,11 +62,6 @@ class UnixFilesystem : public FilesystemInterface { // Returns true if function succeeds. bool MoveFile(const Pathname& old_path, const Pathname& new_path) override; - // This copies a file from old_path to _new_path where "file" can be a plain - // file or directory, which will be copied recursively. - // Returns true if function succeeds - bool CopyFile(const Pathname& old_path, const Pathname& new_path) override; - // Returns true if a pathname is a directory bool IsFolder(const Pathname& pathname) override; diff --git a/webrtc/base/win32filesystem.cc b/webrtc/base/win32filesystem.cc index 4bc2218fa5..519f62a70e 100644 --- a/webrtc/base/win32filesystem.cc +++ b/webrtc/base/win32filesystem.cc @@ -160,12 +160,6 @@ bool Win32Filesystem::IsAbsent(const Pathname& path) { return (ERROR_FILE_NOT_FOUND == err || ERROR_PATH_NOT_FOUND == err); } -bool Win32Filesystem::CopyFile(const Pathname &old_path, - const Pathname &new_path) { - return ::CopyFile(ToUtf16(old_path.pathname()).c_str(), - ToUtf16(new_path.pathname()).c_str(), TRUE) != 0; -} - bool Win32Filesystem::IsTemporaryPath(const Pathname& pathname) { TCHAR buffer[MAX_PATH + 1]; if (!::GetTempPath(arraysize(buffer), buffer)) diff --git a/webrtc/base/win32filesystem.h b/webrtc/base/win32filesystem.h index 3ceaa20b06..9e61436422 100644 --- a/webrtc/base/win32filesystem.h +++ b/webrtc/base/win32filesystem.h @@ -41,10 +41,6 @@ class Win32Filesystem : public FilesystemInterface { // Returns true if the file is successfully moved virtual bool MoveFile(const Pathname &old_path, const Pathname &new_path); - // This copies a file from old_path to _new_path - // Returns true if function succeeds - virtual bool CopyFile(const Pathname &old_path, const Pathname &new_path); - // Returns true if a pathname is a directory virtual bool IsFolder(const Pathname& pathname);