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

Unified Diff: net/base/upload_file_element_reader.cc

Issue 39203004: [Net] Fix error handling on wrong file in UploadData (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 | « chrome_frame/urlmon_upload_data_stream.cc ('k') | net/base/upload_file_element_reader_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/upload_file_element_reader.cc
diff --git a/net/base/upload_file_element_reader.cc b/net/base/upload_file_element_reader.cc
index d1f2a12ac8cd13c6d5037032f13cdd98baf2ea03..77c7705f7f4ebb7e000d0fbe29af7706a81c4c56 100644
--- a/net/base/upload_file_element_reader.cc
+++ b/net/base/upload_file_element_reader.cc
@@ -32,28 +32,29 @@ int InitInternal(const base::FilePath& path,
int64 rv = file_stream->OpenSync(
path, base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ);
if (rv != OK) {
- // If the file can't be opened, we'll just upload an empty file.
+ // If the file can't be opened, the upload should fail.
DLOG(WARNING) << "Failed to open \"" << path.value()
<< "\" for reading: " << rv;
- file_stream.reset();
+ return rv;
} else if (range_offset) {
rv = file_stream->SeekSync(FROM_BEGIN, range_offset);
if (rv < 0) {
DLOG(WARNING) << "Failed to seek \"" << path.value()
<< "\" to offset: " << range_offset << " (" << rv << ")";
- file_stream.reset();
+ return rv;
}
}
int64 length = 0;
- if (file_stream.get() &&
- file_util::GetFileSize(path, &length) &&
- range_offset < static_cast<uint64>(length)) {
+ if (!file_util::GetFileSize(path, &length)) {
+ DLOG(WARNING) << "Failed to get file size of \"" << path.value() << "\"";
+ return ERR_FILE_NOT_FOUND;
+ }
+
+ if (range_offset < static_cast<uint64>(length)) {
// Compensate for the offset.
length = std::min(length - range_offset, range_length);
}
- *out_content_length = length;
- out_file_stream->reset(file_stream.release());
// If the underlying file has been changed and the expected file modification
// time is set, treat it as error. Note that the expected modification time
@@ -61,12 +62,19 @@ int InitInternal(const base::FilePath& path,
// time_t to compare. This check is used for sliced files.
if (!expected_modification_time.is_null()) {
base::PlatformFileInfo info;
- if (file_util::GetFileInfo(path, &info) &&
- expected_modification_time.ToTimeT() != info.last_modified.ToTimeT()) {
+ if (!file_util::GetFileInfo(path, &info)) {
+ DLOG(WARNING) << "Failed to get file info of \"" << path.value() << "\"";
+ return ERR_FILE_NOT_FOUND;
+ }
+
+ if (expected_modification_time.ToTimeT() != info.last_modified.ToTimeT()) {
return ERR_UPLOAD_FILE_CHANGED;
}
}
+ *out_content_length = length;
+ out_file_stream->reset(file_stream.release());
+
return OK;
}
« no previous file with comments | « chrome_frame/urlmon_upload_data_stream.cc ('k') | net/base/upload_file_element_reader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698