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

Side by Side Diff: base/file_util.cc

Issue 18383003: Move DeleteAfterReboot and Move to base namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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_posix.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/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 26 matching lines...) Expand all
37 bool g_bug108724_debug = false; 37 bool g_bug108724_debug = false;
38 38
39 int64 ComputeDirectorySize(const FilePath& root_path) { 39 int64 ComputeDirectorySize(const FilePath& root_path) {
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) {
48 if (from_path.ReferencesParent() || to_path.ReferencesParent())
49 return false;
50 return MoveUnsafe(from_path, to_path);
51 }
52
47 } // namespace base 53 } // namespace base
48 54
49 // ----------------------------------------------------------------------------- 55 // -----------------------------------------------------------------------------
50 56
51 namespace file_util { 57 namespace file_util {
52 58
53 using base::FileEnumerator; 59 using base::FileEnumerator;
54 using base::FilePath; 60 using base::FilePath;
55 using base::kExtensionSeparator; 61 using base::kExtensionSeparator;
56 using base::kMaxUniqueFiles; 62 using base::kMaxUniqueFiles;
57 63
58 void InsertBeforeExtension(FilePath* path, const FilePath::StringType& suffix) {
59 FilePath::StringType& value =
60 const_cast<FilePath::StringType&>(path->value());
61
62 const FilePath::StringType::size_type last_dot =
63 value.rfind(kExtensionSeparator);
64 const FilePath::StringType::size_type last_separator =
65 value.find_last_of(FilePath::StringType(FilePath::kSeparators));
66
67 if (last_dot == FilePath::StringType::npos ||
68 (last_separator != std::wstring::npos && last_dot < last_separator)) {
69 // The path looks something like "C:\pics.old\jojo" or "C:\pics\jojo".
70 // We should just append the suffix to the entire path.
71 value.append(suffix);
72 return;
73 }
74
75 value.insert(last_dot, suffix);
76 }
77
78 bool Move(const FilePath& from_path, const FilePath& to_path) {
79 if (from_path.ReferencesParent() || to_path.ReferencesParent())
80 return false;
81 return MoveUnsafe(from_path, to_path);
82 }
83
84 bool ReplaceFile(const base::FilePath& from_path,
85 const base::FilePath& to_path) {
86 return ReplaceFileAndGetError(from_path, to_path, NULL);
87 }
88
89 bool CopyFile(const FilePath& from_path, const FilePath& to_path) { 64 bool CopyFile(const FilePath& from_path, const FilePath& to_path) {
90 if (from_path.ReferencesParent() || to_path.ReferencesParent()) 65 if (from_path.ReferencesParent() || to_path.ReferencesParent())
91 return false; 66 return false;
92 return CopyFileUnsafe(from_path, to_path); 67 return CopyFileUnsafe(from_path, to_path);
93 } 68 }
94 69
95 bool ContentsEqual(const FilePath& filename1, const FilePath& filename2) { 70 bool ContentsEqual(const FilePath& filename1, const FilePath& filename2) {
96 // 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
97 // 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
98 // doing anything smart with text formatting. 73 // doing anything smart with text formatting.
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 if (!PathExists(new_path) && 255 if (!PathExists(new_path) &&
281 (!have_suffix || !PathExists(FilePath(new_path.value() + suffix)))) { 256 (!have_suffix || !PathExists(FilePath(new_path.value() + suffix)))) {
282 return count; 257 return count;
283 } 258 }
284 } 259 }
285 260
286 return -1; 261 return -1;
287 } 262 }
288 263
289 } // namespace file_util 264 } // namespace file_util
OLDNEW
« no previous file with comments | « base/file_util.h ('k') | base/file_util_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698