From 7405ecd04629d759e6525c134ea375aa3aad83c0 Mon Sep 17 00:00:00 2001 From: "ted.mielczarek@gmail.com" Date: Wed, 15 Dec 2010 16:19:32 +0000 Subject: allow uploading zero-byte files in HTTPUpload R=mark at http://breakpad.appspot.com/243001/show git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@743 4c0a9323-5329-0410-9bdc-e9ce6186880e --- src/common/windows/http_upload.cc | 13 ++++++------- src/common/windows/http_upload.h | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) (limited to 'src/common/windows') diff --git a/src/common/windows/http_upload.cc b/src/common/windows/http_upload.cc index a6879799..ddf61f7f 100644 --- a/src/common/windows/http_upload.cc +++ b/src/common/windows/http_upload.cc @@ -274,8 +274,7 @@ bool HTTPUpload::GenerateRequestBody(const map ¶meters, const wstring &boundary, string *request_body) { vector contents; - GetFileContents(upload_file, &contents); - if (contents.empty()) { + if (!GetFileContents(upload_file, &contents)) { return false; } @@ -322,7 +321,7 @@ bool HTTPUpload::GenerateRequestBody(const map ¶meters, } // static -void HTTPUpload::GetFileContents(const wstring &filename, +bool HTTPUpload::GetFileContents(const wstring &filename, vector *contents) { // The "open" method on pre-MSVC8 ifstream implementations doesn't accept a // wchar_t* filename, so use _wfopen directly in that case. For VC8 and @@ -339,13 +338,13 @@ void HTTPUpload::GetFileContents(const wstring &filename, std::streamoff length = file.tellg(); contents->resize(length); if (length != 0) { - file.seekg(0, ios::beg); - file.read(&((*contents)[0]), length); + file.seekg(0, ios::beg); + file.read(&((*contents)[0]), length); } file.close(); - } else { - contents->clear(); + return true; } + return false; } // static diff --git a/src/common/windows/http_upload.h b/src/common/windows/http_upload.h index f7c69f16..8a17aab1 100644 --- a/src/common/windows/http_upload.h +++ b/src/common/windows/http_upload.h @@ -98,7 +98,7 @@ class HTTPUpload { string *request_body); // Fills the supplied vector with the contents of filename. - static void GetFileContents(const wstring &filename, vector *contents); + static bool GetFileContents(const wstring &filename, vector *contents); // Converts a UTF8 string to UTF16. static wstring UTF8ToWide(const string &utf8); -- cgit v1.2.1