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

Side by Side Diff: base/file_util.cc

Issue 18332014: Move Copy* into the base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: windows Created 7 years, 5 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 | « base/file_util.h ('k') | base/file_util_mac.mm » ('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/file_util.h" 5 #include "base/file_util.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <io.h> 8 #include <io.h>
9 #endif 9 #endif
10 #include <stdio.h> 10 #include <stdio.h>
(...skipping 29 matching lines...) Expand all
40 int64 running_size = 0; 40 int64 running_size = 0;
41 FileEnumerator file_iter(root_path, true, FileEnumerator::FILES); 41 FileEnumerator file_iter(root_path, true, FileEnumerator::FILES);
42 while (!file_iter.Next().empty()) 42 while (!file_iter.Next().empty())
43 running_size += file_iter.GetInfo().GetSize(); 43 running_size += file_iter.GetInfo().GetSize();
44 return running_size; 44 return running_size;
45 } 45 }
46 46
47 bool Move(const FilePath& from_path, const FilePath& to_path) { 47 bool Move(const FilePath& from_path, const FilePath& to_path) {
48 if (from_path.ReferencesParent() || to_path.ReferencesParent()) 48 if (from_path.ReferencesParent() || to_path.ReferencesParent())
49 return false; 49 return false;
50 return MoveUnsafe(from_path, to_path); 50 return internal::MoveUnsafe(from_path, to_path);
51 }
52
53 bool CopyFile(const FilePath& from_path, const FilePath& to_path) {
54 if (from_path.ReferencesParent() || to_path.ReferencesParent())
55 return false;
56 return internal::CopyFileUnsafe(from_path, to_path);
51 } 57 }
52 58
53 } // namespace base 59 } // namespace base
54 60
55 // ----------------------------------------------------------------------------- 61 // -----------------------------------------------------------------------------
56 62
57 namespace file_util { 63 namespace file_util {
58 64
59 using base::FileEnumerator; 65 using base::FileEnumerator;
60 using base::FilePath; 66 using base::FilePath;
61 using base::kExtensionSeparator; 67 using base::kExtensionSeparator;
62 using base::kMaxUniqueFiles; 68 using base::kMaxUniqueFiles;
63 69
64 bool CopyFile(const FilePath& from_path, const FilePath& to_path) {
65 if (from_path.ReferencesParent() || to_path.ReferencesParent())
66 return false;
67 return CopyFileUnsafe(from_path, to_path);
68 }
69
70 bool ContentsEqual(const FilePath& filename1, const FilePath& filename2) { 70 bool ContentsEqual(const FilePath& filename1, const FilePath& filename2) {
71 // We open the file in binary format even if they are text files because 71 // We open the file in binary format even if they are text files because
72 // we are just comparing that bytes are exactly same in both files and not 72 // we are just comparing that bytes are exactly same in both files and not
73 // doing anything smart with text formatting. 73 // doing anything smart with text formatting.
74 std::ifstream file1(filename1.value().c_str(), 74 std::ifstream file1(filename1.value().c_str(),
75 std::ios::in | std::ios::binary); 75 std::ios::in | std::ios::binary);
76 std::ifstream file2(filename2.value().c_str(), 76 std::ifstream file2(filename2.value().c_str(),
77 std::ios::in | std::ios::binary); 77 std::ios::in | std::ios::binary);
78 78
79 // Even if both files aren't openable (and thus, in some sense, "equal"), 79 // Even if both files aren't openable (and thus, in some sense, "equal"),
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 if (!PathExists(new_path) && 255 if (!PathExists(new_path) &&
256 (!have_suffix || !PathExists(FilePath(new_path.value() + suffix)))) { 256 (!have_suffix || !PathExists(FilePath(new_path.value() + suffix)))) {
257 return count; 257 return count;
258 } 258 }
259 } 259 }
260 260
261 return -1; 261 return -1;
262 } 262 }
263 263
264 } // namespace file_util 264 } // namespace file_util
OLDNEW
« no previous file with comments | « base/file_util.h ('k') | base/file_util_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698