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
This commit is contained in:
ted.mielczarek@gmail.com 2010-12-15 16:19:32 +00:00
parent efbe428d83
commit 7405ecd046
2 changed files with 7 additions and 8 deletions

View File

@ -274,8 +274,7 @@ bool HTTPUpload::GenerateRequestBody(const map<wstring, wstring> &parameters,
const wstring &boundary,
string *request_body) {
vector<char> contents;
GetFileContents(upload_file, &contents);
if (contents.empty()) {
if (!GetFileContents(upload_file, &contents)) {
return false;
}
@ -322,7 +321,7 @@ bool HTTPUpload::GenerateRequestBody(const map<wstring, wstring> &parameters,
}
// static
void HTTPUpload::GetFileContents(const wstring &filename,
bool HTTPUpload::GetFileContents(const wstring &filename,
vector<char> *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

View File

@ -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<char> *contents);
static bool GetFileContents(const wstring &filename, vector<char> *contents);
// Converts a UTF8 string to UTF16.
static wstring UTF8ToWide(const string &utf8);