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

Unified Diff: base/file_util_win.cc

Issue 2714016: If CreateDirectory() fails during extension unpacking, log the exact OS call that failed. (Closed) Base URL: git://codf21.jail/chromium.git
Patch Set: Rebase for commit. Created 10 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/file_util.h ('k') | chrome/common/extensions/extension_unpacker.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
}
« no previous file with comments | « base/file_util.h ('k') | chrome/common/extensions/extension_unpacker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698