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 #include <windows.h> | 7 #include <windows.h> |
8 #include <io.h> | 8 #include <io.h> |
9 #include <psapi.h> | 9 #include <psapi.h> |
10 #include <shellapi.h> | 10 #include <shellapi.h> |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
224 return success; | 224 return success; |
225 } | 225 } |
226 | 226 |
227 bool PathExists(const FilePath& path) { | 227 bool PathExists(const FilePath& path) { |
228 ThreadRestrictions::AssertIOAllowed(); | 228 ThreadRestrictions::AssertIOAllowed(); |
229 return (GetFileAttributes(path.value().c_str()) != INVALID_FILE_ATTRIBUTES); | 229 return (GetFileAttributes(path.value().c_str()) != INVALID_FILE_ATTRIBUTES); |
230 } | 230 } |
231 | 231 |
232 bool PathIsWritable(const FilePath& path) { | 232 bool PathIsWritable(const FilePath& path) { |
233 ThreadRestrictions::AssertIOAllowed(); | 233 ThreadRestrictions::AssertIOAllowed(); |
234 HANDLE dir = | 234 win::ScopedHandle dir( |
235 CreateFile(path.value().c_str(), FILE_ADD_FILE, kFileShareAll, | 235 CreateFile(path.value().c_str(), FILE_ADD_FILE, kFileShareAll, |
236 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); | 236 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL)); |
237 | 237 |
238 if (dir == INVALID_HANDLE_VALUE) | 238 if (!dir.IsValid()) |
rvargas (doing something else)
2015/09/16 02:09:12
nit: return dir.IsValid();
brucedawson
2015/09/16 18:29:00
D'oh! Of course.
| |
239 return false; | 239 return false; |
240 | 240 |
241 CloseHandle(dir); | |
242 return true; | 241 return true; |
243 } | 242 } |
244 | 243 |
245 bool DirectoryExists(const FilePath& path) { | 244 bool DirectoryExists(const FilePath& path) { |
246 ThreadRestrictions::AssertIOAllowed(); | 245 ThreadRestrictions::AssertIOAllowed(); |
247 DWORD fileattr = GetFileAttributes(path.value().c_str()); | 246 DWORD fileattr = GetFileAttributes(path.value().c_str()); |
248 if (fileattr != INVALID_FILE_ATTRIBUTES) | 247 if (fileattr != INVALID_FILE_ATTRIBUTES) |
249 return (fileattr & FILE_ATTRIBUTE_DIRECTORY) != 0; | 248 return (fileattr & FILE_ATTRIBUTE_DIRECTORY) != 0; |
250 return false; | 249 return false; |
251 } | 250 } |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
801 // Like Move, this function is not transactional, so we just | 800 // Like Move, this function is not transactional, so we just |
802 // leave the copied bits behind if deleting from_path fails. | 801 // leave the copied bits behind if deleting from_path fails. |
803 // If to_path exists previously then we have already overwritten | 802 // If to_path exists previously then we have already overwritten |
804 // it by now, we don't get better off by deleting the new bits. | 803 // it by now, we don't get better off by deleting the new bits. |
805 } | 804 } |
806 return false; | 805 return false; |
807 } | 806 } |
808 | 807 |
809 } // namespace internal | 808 } // namespace internal |
810 } // namespace base | 809 } // namespace base |
OLD | NEW |