Commit a995c723 authored by Greg Thompson's avatar Greg Thompson Committed by Commit Bot

Improve logging when the installer fails to create a directory.

base::CreateDirectoryAndGetError now ensures that the last error code on
Windows is relevant so that callers may meaningfully use the PLOG family
of macros to get readable error messages.

BUG=874037
R=gab@chromium.org

Change-Id: I6d426c57e0a0ae101e13ebdbe34815ec40801b1e
Reviewed-on: https://chromium-review.googlesource.com/1175782
Commit-Queue: Greg Thompson <grt@chromium.org>
Commit-Queue: Gabriel Charette <gab@chromium.org>
Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583831}
parent da59d447
...@@ -598,8 +598,8 @@ bool CreateDirectoryAndGetError(const FilePath& full_path, ...@@ -598,8 +598,8 @@ bool CreateDirectoryAndGetError(const FilePath& full_path,
AssertBlockingAllowed(); AssertBlockingAllowed();
// If the path exists, we've succeeded if it's a directory, failed otherwise. // 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(); const wchar_t* const full_path_str = full_path.value().c_str();
DWORD fileattr = ::GetFileAttributes(full_path_str); const DWORD fileattr = ::GetFileAttributes(full_path_str);
if (fileattr != INVALID_FILE_ATTRIBUTES) { if (fileattr != INVALID_FILE_ATTRIBUTES) {
if ((fileattr & FILE_ATTRIBUTE_DIRECTORY) != 0) { if ((fileattr & FILE_ATTRIBUTE_DIRECTORY) != 0) {
DVLOG(1) << "CreateDirectory(" << full_path_str << "), " DVLOG(1) << "CreateDirectory(" << full_path_str << "), "
...@@ -608,9 +608,9 @@ bool CreateDirectoryAndGetError(const FilePath& full_path, ...@@ -608,9 +608,9 @@ bool CreateDirectoryAndGetError(const FilePath& full_path,
} }
DLOG(WARNING) << "CreateDirectory(" << full_path_str << "), " DLOG(WARNING) << "CreateDirectory(" << full_path_str << "), "
<< "conflicts with existing file."; << "conflicts with existing file.";
if (error) { if (error)
*error = File::FILE_ERROR_NOT_A_DIRECTORY; *error = File::FILE_ERROR_NOT_A_DIRECTORY;
} ::SetLastError(ERROR_FILE_EXISTS);
return false; return false;
} }
...@@ -621,37 +621,33 @@ bool CreateDirectoryAndGetError(const FilePath& full_path, ...@@ -621,37 +621,33 @@ bool CreateDirectoryAndGetError(const FilePath& full_path,
// directories starting with the highest-level missing parent. // directories starting with the highest-level missing parent.
FilePath parent_path(full_path.DirName()); FilePath parent_path(full_path.DirName());
if (parent_path.value() == full_path.value()) { if (parent_path.value() == full_path.value()) {
if (error) { if (error)
*error = File::FILE_ERROR_NOT_FOUND; *error = File::FILE_ERROR_NOT_FOUND;
} ::SetLastError(ERROR_FILE_NOT_FOUND);
return false; return false;
} }
if (!CreateDirectoryAndGetError(parent_path, error)) { if (!CreateDirectoryAndGetError(parent_path, error)) {
DLOG(WARNING) << "Failed to create one of the parent directories."; DLOG(WARNING) << "Failed to create one of the parent directories.";
if (error) { DCHECK(!error || *error != File::FILE_OK);
DCHECK(*error != File::FILE_OK);
}
return false; return false;
} }
if (!::CreateDirectory(full_path_str, NULL)) { if (::CreateDirectory(full_path_str, NULL))
DWORD error_code = ::GetLastError(); return true;
const DWORD error_code = ::GetLastError();
if (error_code == ERROR_ALREADY_EXISTS && DirectoryExists(full_path)) { if (error_code == ERROR_ALREADY_EXISTS && DirectoryExists(full_path)) {
// This error code ERROR_ALREADY_EXISTS doesn't indicate whether we // This error code ERROR_ALREADY_EXISTS doesn't indicate whether we were
// were racing with someone creating the same directory, or a file // racing with someone creating the same directory, or a file with the same
// with the same path. If DirectoryExists() returns true, we lost the // path. If DirectoryExists() returns true, we lost the race to create the
// race to create the same directory. // same directory.
return true; return true;
} else { }
if (error) if (error)
*error = File::OSErrorToFileError(error_code); *error = File::OSErrorToFileError(error_code);
DLOG(WARNING) << "Failed to create directory " << full_path_str ::SetLastError(error_code);
<< ", last error is " << error_code << "."; DPLOG(WARNING) << "Failed to create directory " << full_path_str;
return false; return false;
}
} else {
return true;
}
} }
bool NormalizeFilePath(const FilePath& path, FilePath* real_path) { bool NormalizeFilePath(const FilePath& path, FilePath* real_path) {
......
...@@ -35,9 +35,12 @@ bool CreateDirWorkItem::DoImpl() { ...@@ -35,9 +35,12 @@ bool CreateDirWorkItem::DoImpl() {
if (top_path_.empty()) if (top_path_.empty())
return true; return true;
VLOG(1) << "top directory that needs to be created: " << top_path_.value(); VLOG(1) << "Top directory that needs to be created: " << top_path_.value();
bool result = base::CreateDirectory(path_); bool result = base::CreateDirectory(path_);
VLOG(1) << "directory creation result: " << result; if (result)
VLOG(1) << "Created directory";
else
PLOG(ERROR) << "Failed to create directory " << top_path_.value();
rollback_needed_ = true; rollback_needed_ = true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment