| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 // If it is, then remove it with RemoveDirectory. | 61 // If it is, then remove it with RemoveDirectory. |
| 62 File::Info file_info; | 62 File::Info file_info; |
| 63 if (GetFileInfo(path, &file_info) && file_info.is_directory) | 63 if (GetFileInfo(path, &file_info) && file_info.is_directory) |
| 64 return RemoveDirectory(path.value().c_str()) != 0; | 64 return RemoveDirectory(path.value().c_str()) != 0; |
| 65 | 65 |
| 66 // 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 |
| 67 // 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 |
| 68 // to SHFileOperation, which will do the right thing. | 68 // to SHFileOperation, which will do the right thing. |
| 69 if (::DeleteFile(path.value().c_str()) != 0) | 69 if (::DeleteFile(path.value().c_str()) != 0) |
| 70 return true; | 70 return true; |
| 71 |
| 72 // If the file doesn't exist, then we are done. This is belt-and-suspenders |
| 73 // for avoiding a SHFileOperation() call on a non-existent file. See |
| 74 // http://crbug.com/368455. |
| 75 if (!PathExists(path)) |
| 76 return true; |
| 71 } | 77 } |
| 72 | 78 |
| 73 // SHFILEOPSTRUCT wants the path to be terminated with two NULLs, | 79 // SHFILEOPSTRUCT wants the path to be terminated with two NULLs, |
| 74 // so we have to use wcscpy because wcscpy_s writes non-NULLs | 80 // so we have to use wcscpy because wcscpy_s writes non-NULLs |
| 75 // into the rest of the buffer. | 81 // into the rest of the buffer. |
| 76 wchar_t double_terminated_path[MAX_PATH + 1] = {0}; | 82 wchar_t double_terminated_path[MAX_PATH + 1] = {0}; |
| 77 #pragma warning(suppress:4996) // don't complain about wcscpy deprecation | 83 #pragma warning(suppress:4996) // don't complain about wcscpy deprecation |
| 78 wcscpy(double_terminated_path, path.value().c_str()); | 84 wcscpy(double_terminated_path, path.value().c_str()); |
| 79 | 85 |
| 80 SHFILEOPSTRUCT file_operation = {0}; | 86 SHFILEOPSTRUCT file_operation = {0}; |
| (...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 // Like Move, this function is not transactional, so we just | 791 // Like Move, this function is not transactional, so we just |
| 786 // leave the copied bits behind if deleting from_path fails. | 792 // leave the copied bits behind if deleting from_path fails. |
| 787 // If to_path exists previously then we have already overwritten | 793 // If to_path exists previously then we have already overwritten |
| 788 // it by now, we don't get better off by deleting the new bits. | 794 // it by now, we don't get better off by deleting the new bits. |
| 789 } | 795 } |
| 790 return false; | 796 return false; |
| 791 } | 797 } |
| 792 | 798 |
| 793 } // namespace internal | 799 } // namespace internal |
| 794 } // namespace base | 800 } // namespace base |
| OLD | NEW |