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

Side by Side Diff: base/file_util_win.cc

Issue 18286004: Move PathExists 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_unittest.cc ('k') | base/files/file_path_watcher_linux.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 #include <windows.h> 7 #include <windows.h>
8 #include <psapi.h> 8 #include <psapi.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #include <shlobj.h> 10 #include <shlobj.h>
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 ThreadRestrictions::AssertIOAllowed(); 173 ThreadRestrictions::AssertIOAllowed();
174 174
175 if (recursive) 175 if (recursive)
176 return ShellCopy(from_path, to_path, true); 176 return ShellCopy(from_path, to_path, true);
177 177
178 // The following code assumes that from path is a directory. 178 // The following code assumes that from path is a directory.
179 DCHECK(file_util::DirectoryExists(from_path)); 179 DCHECK(file_util::DirectoryExists(from_path));
180 180
181 // Instead of creating a new directory, we copy the old one to include the 181 // Instead of creating a new directory, we copy the old one to include the
182 // security information of the folder as part of the copy. 182 // security information of the folder as part of the copy.
183 if (!file_util::PathExists(to_path)) { 183 if (!PathExists(to_path)) {
184 // Except that Vista fails to do that, and instead do a recursive copy if 184 // Except that Vista fails to do that, and instead do a recursive copy if
185 // the target directory doesn't exist. 185 // the target directory doesn't exist.
186 if (base::win::GetVersion() >= base::win::VERSION_VISTA) 186 if (base::win::GetVersion() >= base::win::VERSION_VISTA)
187 file_util::CreateDirectory(to_path); 187 file_util::CreateDirectory(to_path);
188 else 188 else
189 ShellCopy(from_path, to_path, false); 189 ShellCopy(from_path, to_path, false);
190 } 190 }
191 191
192 FilePath directory = from_path.Append(L"*.*"); 192 FilePath directory = from_path.Append(L"*.*");
193 return ShellCopy(directory, to_path, false); 193 return ShellCopy(directory, to_path, false);
194 } 194 }
195 195
196 bool PathExists(const FilePath& path) {
197 ThreadRestrictions::AssertIOAllowed();
198 return (GetFileAttributes(path.value().c_str()) != INVALID_FILE_ATTRIBUTES);
199 }
200
196 } // namespace base 201 } // namespace base
197 202
198 // ----------------------------------------------------------------------------- 203 // -----------------------------------------------------------------------------
199 204
200 namespace file_util { 205 namespace file_util {
201 206
202 using base::FilePath; 207 using base::FilePath;
203 using base::kFileShareAll; 208 using base::kFileShareAll;
204 209
205 bool PathExists(const FilePath& path) {
206 base::ThreadRestrictions::AssertIOAllowed();
207 return (GetFileAttributes(path.value().c_str()) != INVALID_FILE_ATTRIBUTES);
208 }
209
210 bool PathIsWritable(const FilePath& path) { 210 bool PathIsWritable(const FilePath& path) {
211 base::ThreadRestrictions::AssertIOAllowed(); 211 base::ThreadRestrictions::AssertIOAllowed();
212 HANDLE dir = 212 HANDLE dir =
213 CreateFile(path.value().c_str(), FILE_ADD_FILE, kFileShareAll, 213 CreateFile(path.value().c_str(), FILE_ADD_FILE, kFileShareAll,
214 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); 214 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
215 215
216 if (dir == INVALID_HANDLE_VALUE) 216 if (dir == INVALID_HANDLE_VALUE)
217 return false; 217 return false;
218 218
219 CloseHandle(dir); 219 CloseHandle(dir);
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 // Like Move, this function is not transactional, so we just 749 // Like Move, this function is not transactional, so we just
750 // leave the copied bits behind if deleting from_path fails. 750 // leave the copied bits behind if deleting from_path fails.
751 // If to_path exists previously then we have already overwritten 751 // If to_path exists previously then we have already overwritten
752 // it by now, we don't get better off by deleting the new bits. 752 // it by now, we don't get better off by deleting the new bits.
753 } 753 }
754 return false; 754 return false;
755 } 755 }
756 756
757 } // namespace internal 757 } // namespace internal
758 } // namespace base 758 } // namespace base
OLDNEW
« no previous file with comments | « base/file_util_unittest.cc ('k') | base/files/file_path_watcher_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698