Index: base/file_util_win.cc |
diff --git a/base/file_util_win.cc b/base/file_util_win.cc |
index dc15ea069807939115867ad4104335ba234aa8ac..8a15370c46331356f576cbdae6a38f30de24b431 100644 |
--- a/base/file_util_win.cc |
+++ b/base/file_util_win.cc |
@@ -587,22 +587,32 @@ bool CreateNewTempDirectory(const FilePath::StringType& prefix, |
return CreateTemporaryDirInDir(system_temp_dir, prefix, new_temp_path); |
} |
+bool CreateDirectory(const FilePath& full_path) { |
+ return file_util::CreateDirectoryExtraLogging(full_path, LOG(INFO)); |
+} |
+ |
// TODO(skerner): Extra logging has been added to understand crbug/35198 . |
// Remove it once we get a log from a user who can reproduce the issue. |
-bool CreateDirectory(const FilePath& full_path) { |
- LOG(INFO) << "Enter CreateDirectory: full_path = " << full_path.value(); |
+bool CreateDirectoryExtraLogging(const FilePath& full_path, |
+ std::ostream& log) { |
+ log << "Enter CreateDirectory: full_path = " << full_path.value() |
+ << std::endl; |
// If the path exists, we've succeeded if it's a directory, failed otherwise. |
const wchar_t* full_path_str = full_path.value().c_str(); |
DWORD fileattr = ::GetFileAttributes(full_path_str); |
- LOG(INFO) << "::GetFileAttributes() returned " << fileattr; |
- if (fileattr != INVALID_FILE_ATTRIBUTES) { |
+ log << "::GetFileAttributes() returned " << fileattr << std::endl; |
+ if (fileattr == INVALID_FILE_ATTRIBUTES) { |
+ DWORD fileattr_error = GetLastError(); |
+ log << "::GetFileAttributes() failed. GetLastError() = " |
+ << fileattr_error << std::endl; |
+ } else { |
if ((fileattr & FILE_ATTRIBUTE_DIRECTORY) != 0) { |
- LOG(INFO) << "CreateDirectory(" << full_path_str << "), " << |
- "directory already exists."; |
+ log << "CreateDirectory(" << full_path_str << "), " |
+ << "directory already exists." << std::endl; |
return true; |
} else { |
- LOG(WARNING) << "CreateDirectory(" << full_path_str << "), " << |
- "conflicts with existing file."; |
+ log << "CreateDirectory(" << full_path_str << "), " |
+ << "conflicts with existing file." << std::endl; |
} |
} |
@@ -613,35 +623,49 @@ bool CreateDirectory(const FilePath& full_path) { |
// directories starting with the highest-level missing parent. |
FilePath parent_path(full_path.DirName()); |
if (parent_path.value() == full_path.value()) { |
- LOG(INFO) << "Can't create directory: parent_path " << |
- parent_path.value() << " should not equal full_path " << |
- full_path.value(); |
+ log << "Can't create directory: parent_path " << parent_path.value() |
+ << " should not equal full_path " << full_path.value() |
+ << std::endl; |
return false; |
} |
if (!CreateDirectory(parent_path)) { |
- LOG(INFO) << "Failed to create one of the parent directories: " << |
- parent_path.value(); |
+ log << "Failed to create one of the parent directories: " |
+ << parent_path.value() << std::endl; |
return false; |
} |
- LOG(INFO) << "About to call ::CreateDirectory() with full_path_str = " << |
- full_path_str; |
+ log << "About to call ::CreateDirectory() with full_path_str = " |
+ << full_path_str << std::endl; |
if (!::CreateDirectory(full_path_str, NULL)) { |
DWORD error_code = ::GetLastError(); |
+ log << "CreateDirectory() gave last error " << error_code << std::endl; |
+ |
+ DWORD fileattr = GetFileAttributes(full_path.value().c_str()); |
+ if (fileattr == INVALID_FILE_ATTRIBUTES) { |
+ DWORD fileattr_error = ::GetLastError(); |
+ log << "GetFileAttributes() failed, GetLastError() = " |
+ << fileattr_error << std::endl; |
+ } else { |
+ log << "GetFileAttributes() returned " << fileattr << std::endl; |
+ log << "Is the path a directory: " |
+ << ((fileattr & FILE_ATTRIBUTE_DIRECTORY) != 0) << std::endl; |
+ } |
if (error_code == ERROR_ALREADY_EXISTS && DirectoryExists(full_path)) { |
// This error code doesn't indicate whether we were racing with someone |
// creating the same directory, or a file with the same path, therefore |
// we check. |
- LOG(INFO) << "Race condition? Directory already exists: " << |
- full_path.value(); |
+ log << "Race condition? Directory already exists: " |
+ << full_path.value() << std::endl; |
return true; |
} else { |
- LOG(WARNING) << "Failed to create directory " << full_path_str << |
- ", le=" << error_code; |
+ DWORD dir_exists_error = ::GetLastError(); |
+ log << "Failed to create directory " << full_path_str << std::endl; |
+ log << "GetLastError() for DirectoryExists() is " |
+ << dir_exists_error << std::endl; |
return false; |
} |
} else { |
- LOG(INFO) << "::CreateDirectory() worked."; |
+ log << "::CreateDirectory() succeeded." << std::endl; |
return true; |
} |
} |