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

Side by Side Diff: trunk/src/base/test/test_file_util_posix.cc

Issue 13958002: Revert 192940 "Delete CopyRecursiveDirNoCache from test_file_util." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « trunk/src/base/test/test_file_util.h ('k') | trunk/src/base/test/test_file_util_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/test/test_file_util.h" 5 #include "base/test/test_file_util.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 #include <sys/types.h> 10 #include <sys/types.h>
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 } 71 }
72 72
73 } // namespace 73 } // namespace
74 74
75 bool DieFileDie(const base::FilePath& file, bool recurse) { 75 bool DieFileDie(const base::FilePath& file, bool recurse) {
76 // There is no need to workaround Windows problems on POSIX. 76 // There is no need to workaround Windows problems on POSIX.
77 // Just pass-through. 77 // Just pass-through.
78 return file_util::Delete(file, recurse); 78 return file_util::Delete(file, recurse);
79 } 79 }
80 80
81 // Mostly a verbatim copy of CopyDirectory
82 bool CopyRecursiveDirNoCache(const base::FilePath& source_dir,
83 const base::FilePath& dest_dir) {
84 char top_dir[PATH_MAX];
85 if (base::strlcpy(top_dir, source_dir.value().c_str(),
86 arraysize(top_dir)) >= arraysize(top_dir)) {
87 return false;
88 }
89
90 // This function does not properly handle destinations within the source
91 base::FilePath real_to_path = dest_dir;
92 if (PathExists(real_to_path)) {
93 if (!AbsolutePath(&real_to_path))
94 return false;
95 } else {
96 real_to_path = real_to_path.DirName();
97 if (!AbsolutePath(&real_to_path))
98 return false;
99 }
100 if (real_to_path.value().compare(0, source_dir.value().size(),
101 source_dir.value()) == 0)
102 return false;
103
104 bool success = true;
105 int traverse_type = FileEnumerator::FILES |
106 FileEnumerator::SHOW_SYM_LINKS | FileEnumerator::DIRECTORIES;
107 FileEnumerator traversal(source_dir, true, traverse_type);
108
109 // dest_dir may not exist yet, start the loop with dest_dir
110 FileEnumerator::FindInfo info;
111 base::FilePath current = source_dir;
112 if (stat(source_dir.value().c_str(), &info.stat) < 0) {
113 DLOG(ERROR) << "CopyRecursiveDirNoCache() couldn't stat source directory: "
114 << source_dir.value() << " errno = " << errno;
115 success = false;
116 }
117
118 while (success && !current.empty()) {
119 // |current| is the source path, including source_dir, so paste
120 // the suffix after source_dir onto dest_dir to create the target_path.
121 std::string suffix(&current.value().c_str()[source_dir.value().size()]);
122 // Strip the leading '/' (if any).
123 if (!suffix.empty()) {
124 DCHECK_EQ('/', suffix[0]);
125 suffix.erase(0, 1);
126 }
127 const base::FilePath target_path = dest_dir.Append(suffix);
128
129 if (S_ISDIR(info.stat.st_mode)) {
130 if (mkdir(target_path.value().c_str(), info.stat.st_mode & 01777) != 0 &&
131 errno != EEXIST) {
132 DLOG(ERROR) << "CopyRecursiveDirNoCache() couldn't create directory: "
133 << target_path.value() << " errno = " << errno;
134 success = false;
135 }
136 } else if (S_ISREG(info.stat.st_mode)) {
137 if (CopyFile(current, target_path)) {
138 success = EvictFileFromSystemCache(target_path);
139 DCHECK(success);
140 } else {
141 DLOG(ERROR) << "CopyRecursiveDirNoCache() couldn't create file: "
142 << target_path.value();
143 success = false;
144 }
145 } else {
146 DLOG(WARNING) << "CopyRecursiveDirNoCache() skipping non-regular file: "
147 << current.value();
148 }
149
150 current = traversal.Next();
151 traversal.GetFindInfo(&info);
152 }
153
154 return success;
155 }
156
81 #if !defined(OS_LINUX) && !defined(OS_MACOSX) 157 #if !defined(OS_LINUX) && !defined(OS_MACOSX)
82 bool EvictFileFromSystemCache(const base::FilePath& file) { 158 bool EvictFileFromSystemCache(const base::FilePath& file) {
83 // There doesn't seem to be a POSIX way to cool the disk cache. 159 // There doesn't seem to be a POSIX way to cool the disk cache.
84 NOTIMPLEMENTED(); 160 NOTIMPLEMENTED();
85 return false; 161 return false;
86 } 162 }
87 #endif 163 #endif
88 164
89 std::wstring FilePathAsWString(const base::FilePath& path) { 165 std::wstring FilePathAsWString(const base::FilePath& path) {
90 return UTF8ToWide(path.value()); 166 return UTF8ToWide(path.value());
(...skipping 16 matching lines...) Expand all
107 DCHECK(info_ != NULL); 183 DCHECK(info_ != NULL);
108 DCHECK_NE(0u, length_); 184 DCHECK_NE(0u, length_);
109 } 185 }
110 186
111 PermissionRestorer::~PermissionRestorer() { 187 PermissionRestorer::~PermissionRestorer() {
112 if (!RestorePermissionInfo(path_, info_, length_)) 188 if (!RestorePermissionInfo(path_, info_, length_))
113 NOTREACHED(); 189 NOTREACHED();
114 } 190 }
115 191
116 } // namespace file_util 192 } // namespace file_util
OLDNEW
« no previous file with comments | « trunk/src/base/test/test_file_util.h ('k') | trunk/src/base/test/test_file_util_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698