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

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, 2 months 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
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..1c7cd44f71b70dcff032358b8ccf2e28976dd001 100644
--- a/net/base/upload_file_element_reader.cc
+++ b/net/base/upload_file_element_reader.cc
@@ -28,27 +28,33 @@ int InitInternal(const base::FilePath& path,
const base::Time& expected_modification_time,
scoped_ptr<FileStream, FileStreamDeleter>* out_file_stream,
uint64* out_content_length) {
+ out_file_stream->reset();
+ *out_content_length = 0;
+
scoped_ptr<FileStream> file_stream(new FileStream(NULL));
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);
}
@@ -61,8 +67,12 @@ 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;
mmenke 2013/10/29 15:29:31 I suggest not setting out_content_length or out_fi
tzik 2013/11/07 04:42:55 Done.
+ }
+
+ if (expected_modification_time.ToTimeT() != info.last_modified.ToTimeT()) {
return ERR_UPLOAD_FILE_CHANGED;
}
}
« no previous file with comments | « no previous file | net/base/upload_file_element_reader_unittest.cc » ('j') | net/http/http_network_transaction_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698