summaryrefslogtreecommitdiffstats
path: root/base/file_util_win.cc
diff options
context:
space:
mode:
authorzork@chromium.org <zork@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-07 00:05:36 +0000
committerzork@chromium.org <zork@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-07 00:05:36 +0000
commit3a51cfdd1775075f13dab50f6d8a9cb04bd6beb9 (patch)
treed5357e00d02dc654a1f3b9593bbeaac900e0f30a /base/file_util_win.cc
parent7473b624aff7e1db5b22d7a856d1f21509fa04bc (diff)
downloadchromium_src-3a51cfdd1775075f13dab50f6d8a9cb04bd6beb9.zip
chromium_src-3a51cfdd1775075f13dab50f6d8a9cb04bd6beb9.tar.gz
chromium_src-3a51cfdd1775075f13dab50f6d8a9cb04bd6beb9.tar.bz2
Revert 46633 - Windows: Make file_util::Delete("c:\\foo_dir", false) work correctly. Add more unit tests for Delete.
BUG=42374 TEST=included Review URL: http://codereview.chromium.org/1763008 TBR=thestig@chromium.org Review URL: http://codereview.chromium.org/2038004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46640 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util_win.cc')
-rw-r--r--base/file_util_win.cc27
1 files changed, 9 insertions, 18 deletions
diff --git a/base/file_util_win.cc b/base/file_util_win.cc
index 4f96ef3..8d502e7 100644
--- a/base/file_util_win.cc
+++ b/base/file_util_win.cc
@@ -73,19 +73,11 @@ bool Delete(const FilePath& path, bool recursive) {
if (path.value().length() >= MAX_PATH)
return false;
- if (!recursive) {
- // If not recursing, then first check to see if |path| is a directory.
- // If it is, then remove it with RemoveDirectory.
- FileInfo file_info;
- if (GetFileInfo(path, &file_info) && file_info.is_directory)
- return RemoveDirectory(path.value().c_str()) != 0;
-
- // Otherwise, it's a file, wildcard or non-existant. Try DeleteFile first
- // because it should be faster. If DeleteFile fails, then we fall through
- // to SHFileOperation, which will do the right thing.
- if (DeleteFile(path.value().c_str()) != 0)
- return true;
- }
+ // If we're not recursing use DeleteFile; it should be faster. DeleteFile
+ // fails if passed a directory though, which is why we fall through on
+ // failure to the SHFileOperation.
+ if (!recursive && DeleteFile(path.value().c_str()) != 0)
+ return true;
// SHFILEOPSTRUCT wants the path to be terminated with two NULLs,
// so we have to use wcscpy because wcscpy_s writes non-NULLs
@@ -101,10 +93,9 @@ bool Delete(const FilePath& path, bool recursive) {
if (!recursive)
file_operation.fFlags |= FOF_NORECURSION | FOF_FILESONLY;
int err = SHFileOperation(&file_operation);
- // Some versions of Windows return ERROR_FILE_NOT_FOUND (0x2) when deleting
- // an empty directory and some return 0x402 when they should be returning
- // ERROR_FILE_NOT_FOUND. MSDN says Vista and up won't return 0x402.
- return (err == 0 || err == ERROR_FILE_NOT_FOUND || err == 0x402);
+ // Some versions of Windows return ERROR_FILE_NOT_FOUND when
+ // deleting an empty directory.
+ return (err == 0 || err == ERROR_FILE_NOT_FOUND);
}
bool DeleteAfterReboot(const FilePath& path) {
@@ -609,7 +600,7 @@ bool CreateDirectory(const FilePath& full_path) {
bool GetFileInfo(const FilePath& file_path, FileInfo* results) {
WIN32_FILE_ATTRIBUTE_DATA attr;
- if (!GetFileAttributesEx(file_path.value().c_str(),
+ if (!GetFileAttributesEx(file_path.ToWStringHack().c_str(),
GetFileExInfoStandard, &attr)) {
return false;
}