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

Side by Side Diff: base/file_util_win.cc

Issue 296113003: Make DeleteFile succeed on Windows 7 even if the path contains a nonexistent directory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed formatting, added unit test Created 6 years, 7 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') | no next file » | 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 87
88 // Since we're passing flags to the operation telling it to be silent, 88 // Since we're passing flags to the operation telling it to be silent,
89 // it's possible for the operation to be aborted/cancelled without err 89 // it's possible for the operation to be aborted/cancelled without err
90 // being set (although MSDN doesn't give any scenarios for how this can 90 // being set (although MSDN doesn't give any scenarios for how this can
91 // happen). See MSDN for SHFileOperation and SHFILEOPTSTRUCT. 91 // happen). See MSDN for SHFileOperation and SHFILEOPTSTRUCT.
92 if (file_operation.fAnyOperationsAborted) 92 if (file_operation.fAnyOperationsAborted)
93 return false; 93 return false;
94 94
95 // Some versions of Windows return ERROR_FILE_NOT_FOUND (0x2) when deleting 95 // Some versions of Windows return ERROR_FILE_NOT_FOUND (0x2) when deleting
96 // an empty directory and some return 0x402 when they should be returning 96 // an empty directory and some return 0x402 when they should be returning
97 // ERROR_FILE_NOT_FOUND. MSDN says Vista and up won't return 0x402. 97 // ERROR_FILE_NOT_FOUND. MSDN says Vista and up won't return 0x402. Windows 7
98 return (err == 0 || err == ERROR_FILE_NOT_FOUND || err == 0x402); 98 // can return DE_INVALIDFILES (0x7C) for nonexistent directories.
99 return (err == 0 || err == ERROR_FILE_NOT_FOUND || err == 0x402 ||
100 err == 0x7C);
99 } 101 }
100 102
101 bool DeleteFileAfterReboot(const FilePath& path) { 103 bool DeleteFileAfterReboot(const FilePath& path) {
102 ThreadRestrictions::AssertIOAllowed(); 104 ThreadRestrictions::AssertIOAllowed();
103 105
104 if (path.value().length() >= MAX_PATH) 106 if (path.value().length() >= MAX_PATH)
105 return false; 107 return false;
106 108
107 return MoveFileEx(path.value().c_str(), NULL, 109 return MoveFileEx(path.value().c_str(), NULL,
108 MOVEFILE_DELAY_UNTIL_REBOOT | 110 MOVEFILE_DELAY_UNTIL_REBOOT |
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 // Like Move, this function is not transactional, so we just 787 // Like Move, this function is not transactional, so we just
786 // leave the copied bits behind if deleting from_path fails. 788 // leave the copied bits behind if deleting from_path fails.
787 // If to_path exists previously then we have already overwritten 789 // 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. 790 // it by now, we don't get better off by deleting the new bits.
789 } 791 }
790 return false; 792 return false;
791 } 793 }
792 794
793 } // namespace internal 795 } // namespace internal
794 } // namespace base 796 } // namespace base
OLDNEW
« no previous file with comments | « base/file_util_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698