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

Unified Diff: base/file_util_linux.cc

Issue 2441: implement things needed to run net/disk_cache/backend_unittest (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 12 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/file_util.h ('k') | base/file_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « base/file_util.h ('k') | base/file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698