OLD | NEW |
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/files/file_util.h" | 5 #include "base/files/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 Loading... |
40 running_size += file_iter.GetInfo().GetSize(); | 40 running_size += file_iter.GetInfo().GetSize(); |
41 return running_size; | 41 return running_size; |
42 } | 42 } |
43 | 43 |
44 bool Move(const FilePath& from_path, const FilePath& to_path) { | 44 bool Move(const FilePath& from_path, const FilePath& to_path) { |
45 if (from_path.ReferencesParent() || to_path.ReferencesParent()) | 45 if (from_path.ReferencesParent() || to_path.ReferencesParent()) |
46 return false; | 46 return false; |
47 return internal::MoveUnsafe(from_path, to_path); | 47 return internal::MoveUnsafe(from_path, to_path); |
48 } | 48 } |
49 | 49 |
50 bool CopyFile(const FilePath& from_path, const FilePath& to_path) { | |
51 if (from_path.ReferencesParent() || to_path.ReferencesParent()) | |
52 return false; | |
53 return internal::CopyFileUnsafe(from_path, to_path); | |
54 } | |
55 | |
56 bool ContentsEqual(const FilePath& filename1, const FilePath& filename2) { | 50 bool ContentsEqual(const FilePath& filename1, const FilePath& filename2) { |
57 // We open the file in binary format even if they are text files because | 51 // We open the file in binary format even if they are text files because |
58 // we are just comparing that bytes are exactly same in both files and not | 52 // we are just comparing that bytes are exactly same in both files and not |
59 // doing anything smart with text formatting. | 53 // doing anything smart with text formatting. |
60 std::ifstream file1(filename1.value().c_str(), | 54 std::ifstream file1(filename1.value().c_str(), |
61 std::ios::in | std::ios::binary); | 55 std::ios::in | std::ios::binary); |
62 std::ifstream file2(filename2.value().c_str(), | 56 std::ifstream file2(filename2.value().c_str(), |
63 std::ios::in | std::ios::binary); | 57 std::ios::in | std::ios::binary); |
64 | 58 |
65 // Even if both files aren't openable (and thus, in some sense, "equal"), | 59 // Even if both files aren't openable (and thus, in some sense, "equal"), |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 if (!PathExists(new_path) && | 246 if (!PathExists(new_path) && |
253 (!have_suffix || !PathExists(FilePath(new_path.value() + suffix)))) { | 247 (!have_suffix || !PathExists(FilePath(new_path.value() + suffix)))) { |
254 return count; | 248 return count; |
255 } | 249 } |
256 } | 250 } |
257 | 251 |
258 return -1; | 252 return -1; |
259 } | 253 } |
260 | 254 |
261 } // namespace base | 255 } // namespace base |
OLD | NEW |