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

Unified Diff: content/browser/download/base_file.cc

Issue 11571025: Initial CL for Downloads resumption. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporated Pawel's comment. Created 7 years, 11 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
« no previous file with comments | « chrome/browser/plugins/plugin_installer.cc ('k') | content/browser/download/base_file_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/download/base_file.cc
diff --git a/content/browser/download/base_file.cc b/content/browser/download/base_file.cc
index 9d55828f5ecbe0e73b9138239899601c7a0fed07..1682723da5b5d618b07c880c43f58424ddf5d556 100644
--- a/content/browser/download/base_file.cc
+++ b/content/browser/download/base_file.cc
@@ -296,6 +296,24 @@ DownloadInterruptReason BaseFile::Open() {
file_stream_->SetBoundNetLogSource(bound_net_log_);
}
+ int64 file_size = file_stream_->SeekSync(net::FROM_END, 0);
+ if (file_size > bytes_so_far_) {
+ // The file is larger than we expected.
+ // This is OK, as long as we don't use the extra.
+ // Truncate the file.
+ int64 truncate_result = file_stream_->Truncate(bytes_so_far_);
+ if (truncate_result < 0)
+ return LogNetError("Truncate", static_cast<net::Error>(truncate_result));
+
+ // If if wasn't an error, it should have truncated to the size
+ // specified.
+ DCHECK_EQ(bytes_so_far_, truncate_result);
+ } else if (file_size < bytes_so_far_) {
+ // The file is shorter than we expected. Our hashes won't be valid.
+ return LogInterruptReason("Unable to seek to last written point", 0,
+ DOWNLOAD_INTERRUPT_REASON_FILE_TOO_SHORT);
+ }
+
return DOWNLOAD_INTERRUPT_REASON_NONE;
}
« no previous file with comments | « chrome/browser/plugins/plugin_installer.cc ('k') | content/browser/download/base_file_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698