diff options
author | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-17 17:00:04 +0000 |
---|---|---|
committer | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-17 17:00:04 +0000 |
commit | 3b95b86342778c3a18b70158280332c0601516c9 (patch) | |
tree | 3baeb2e90f6a0160cfe9c6763f13d5d339bb7229 /base/file_util_win.cc | |
parent | bc9147a10c7287f285ddc1c246cc9d38cd5987c4 (diff) | |
download | chromium_src-3b95b86342778c3a18b70158280332c0601516c9.zip chromium_src-3b95b86342778c3a18b70158280332c0601516c9.tar.gz chromium_src-3b95b86342778c3a18b70158280332c0601516c9.tar.bz2 |
Adds logging to file_util::WriteFile to figure out why writing
bookmarks is failing for some people. As a result of this I moved some
code from common/win_util to base/win_util so that file_util_win could
call it. The only changes to this code are formatting.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/2931
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2312 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util_win.cc')
-rw-r--r-- | base/file_util_win.cc | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/base/file_util_win.cc b/base/file_util_win.cc index f2822d1..168e26e 100644 --- a/base/file_util_win.cc +++ b/base/file_util_win.cc @@ -477,18 +477,29 @@ int WriteFile(const std::wstring& filename, const char* data, int size) { CREATE_ALWAYS, 0, NULL)); - if (file == INVALID_HANDLE_VALUE) + if (file == INVALID_HANDLE_VALUE) { + LOG(WARNING) << "CreateFile failed for path " << filename << + " error code=" << GetLastError() << + " error text=" << win_util::FormatLastWin32Error(); return -1; + } - int ret_value; DWORD written; - if (::WriteFile(file, data, size, &written, NULL) && written == size) { - ret_value = static_cast<int>(written); + BOOL result = ::WriteFile(file, data, size, &written, NULL); + if (result && written == size) + return static_cast<int>(written); + + if (!result) { + // WriteFile failed. + LOG(WARNING) << "writing file " << filename << + " failed, error code=" << GetLastError() << + " description=" << win_util::FormatLastWin32Error(); } else { - ret_value = -1; + // Didn't write all the bytes. + LOG(WARNING) << "wrote" << written << " bytes to " << filename << + " expected " << size; } - - return ret_value; + return -1; } bool RenameFileAndResetSecurityDescriptor( |