summaryrefslogtreecommitdiffstats
path: root/content/browser/download/base_file.cc
diff options
context:
space:
mode:
authorrdsmith@chromium.org <rdsmith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-12 15:57:10 +0000
committerrdsmith@chromium.org <rdsmith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-12 15:57:10 +0000
commit8d68a3e0b0c300cbb8a61aae64cf1b28c10ab93e (patch)
tree52890906250ace5c098d0fe926aca72bc7ffb9c2 /content/browser/download/base_file.cc
parentf24083dd121de728df41d5c3ed579d9e6cbde3d1 (diff)
downloadchromium_src-8d68a3e0b0c300cbb8a61aae64cf1b28c10ab93e.zip
chromium_src-8d68a3e0b0c300cbb8a61aae64cf1b28c10ab93e.tar.gz
chromium_src-8d68a3e0b0c300cbb8a61aae64cf1b28c10ab93e.tar.bz2
Initial CL for Downloads resumption.
(Original work done by ahendrickson@chromium.org) BUG=7648 R=ahendrickson@chromium.org R=asanka@chromium.org Review URL: https://chromiumcodereview.appspot.com/11571025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@176530 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/download/base_file.cc')
-rw-r--r--content/browser/download/base_file.cc18
1 files changed, 18 insertions, 0 deletions
diff --git a/content/browser/download/base_file.cc b/content/browser/download/base_file.cc
index 9d55828..1682723 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;
}