| Index: base/file_util_linux.cc
|
| ===================================================================
|
| --- base/file_util_linux.cc (revision 2109)
|
| +++ base/file_util_linux.cc (working copy)
|
| @@ -25,6 +25,7 @@
|
| return true;
|
| }
|
|
|
| +// Does not copy attributes, permissions, metadata etc.
|
| bool CopyFile(const std::wstring& from_path, const std::wstring& to_path) {
|
| int infile = open(WideToUTF8(from_path).c_str(), O_RDONLY);
|
| if (infile < 0)
|
| @@ -71,4 +72,49 @@
|
| return result;
|
| }
|
|
|
| +// TODO: Make this function symlink-aware.
|
| +// Does not copy attributes, permissions, metadata etc.
|
| +bool CopyDirectory(const std::wstring& from_path, const std::wstring& to_path,
|
| + bool recursive) {
|
| + if (!CreateDirectory(to_path)) {
|
| + return false;
|
| + }
|
| +
|
| + FileEnumerator enumerator(from_path, false, FileEnumerator::FILES);
|
| + std::wstring path;
|
| + while ((path = enumerator.Next()) != L"") {
|
| + path = GetFilenameFromPath(path);
|
| + std::wstring from = from_path;
|
| + AppendToPath(&from, path);
|
| +
|
| + std::wstring to = to_path;
|
| + AppendToPath(&to, path);
|
| +
|
| + if (!CopyFile(from, to)) {
|
| + // If some files have been copied successfully they won't be deleted.
|
| + return false;
|
| + }
|
| + }
|
| +
|
| + if (recursive) {
|
| + FileEnumerator enumerator(from_path, false, FileEnumerator::DIRECTORIES);
|
| + std::wstring path;
|
| + while ((path = enumerator.Next()) != L"") {
|
| + path = GetFilenameFromPath(path);
|
| + std::wstring from = from_path;
|
| + AppendToPath(&from, path);
|
| +
|
| + std::wstring to = to_path;
|
| + AppendToPath(&to, path);
|
| +
|
| + if (!CopyDirectory(from, to, true)) {
|
| + // If some files have been copied successfully they won't be deleted.
|
| + return false;
|
| + }
|
| + }
|
| + }
|
| +
|
| + return true;
|
| +}
|
| +
|
| } // namespace file_util
|
|
|