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/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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 return FilePath(); | 44 return FilePath(); |
45 return FilePath(file_path); | 45 return FilePath(file_path); |
46 } | 46 } |
47 | 47 |
48 bool DeleteFile(const FilePath& path, bool recursive) { | 48 bool DeleteFile(const FilePath& path, bool recursive) { |
49 ThreadRestrictions::AssertIOAllowed(); | 49 ThreadRestrictions::AssertIOAllowed(); |
50 | 50 |
51 if (path.value().length() >= MAX_PATH) | 51 if (path.value().length() >= MAX_PATH) |
52 return false; | 52 return false; |
53 | 53 |
| 54 // On XP SHFileOperation will return ERROR_ACCESS_DENIED instead of |
| 55 // ERROR_FILE_NOT_FOUND, so just shortcut this here. |
| 56 if (path.empty()) |
| 57 return true; |
| 58 |
54 if (!recursive) { | 59 if (!recursive) { |
55 // If not recursing, then first check to see if |path| is a directory. | 60 // If not recursing, then first check to see if |path| is a directory. |
56 // If it is, then remove it with RemoveDirectory. | 61 // If it is, then remove it with RemoveDirectory. |
57 File::Info file_info; | 62 File::Info file_info; |
58 if (GetFileInfo(path, &file_info) && file_info.is_directory) | 63 if (GetFileInfo(path, &file_info) && file_info.is_directory) |
59 return RemoveDirectory(path.value().c_str()) != 0; | 64 return RemoveDirectory(path.value().c_str()) != 0; |
60 | 65 |
61 // Otherwise, it's a file, wildcard or non-existant. Try DeleteFile first | 66 // Otherwise, it's a file, wildcard or non-existant. Try DeleteFile first |
62 // because it should be faster. If DeleteFile fails, then we fall through | 67 // because it should be faster. If DeleteFile fails, then we fall through |
63 // to SHFileOperation, which will do the right thing. | 68 // to SHFileOperation, which will do the right thing. |
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 // Like Move, this function is not transactional, so we just | 785 // Like Move, this function is not transactional, so we just |
781 // leave the copied bits behind if deleting from_path fails. | 786 // leave the copied bits behind if deleting from_path fails. |
782 // If to_path exists previously then we have already overwritten | 787 // If to_path exists previously then we have already overwritten |
783 // it by now, we don't get better off by deleting the new bits. | 788 // it by now, we don't get better off by deleting the new bits. |
784 } | 789 } |
785 return false; | 790 return false; |
786 } | 791 } |
787 | 792 |
788 } // namespace internal | 793 } // namespace internal |
789 } // namespace base | 794 } // namespace base |
OLD | NEW |