summaryrefslogtreecommitdiff
path: root/content/browser/download/base_file.cc
diff options
context:
space:
mode:
authorTorne (Richard Coles) <torne@google.com>2013-03-28 15:31:22 +0000
committerTorne (Richard Coles) <torne@google.com>2013-03-28 15:31:22 +0000
commit2a99a7e74a7f215066514fe81d2bfa6639d9eddd (patch)
tree7c2d04841fcd599fd83b0f0bb1100e1c89a35bae /content/browser/download/base_file.cc
parent61c449bbbb53310a8c041d8cefdd6b01a126cc7e (diff)
downloadchromium_org-2a99a7e74a7f215066514fe81d2bfa6639d9eddd.tar.gz
Merge from Chromium at DEPS revision r190564
This commit was generated by merge_to_master.py. Change-Id: Icadecbce29854b8fa25fd335b2c1949b5ca5d170
Diffstat (limited to 'content/browser/download/base_file.cc')
-rw-r--r--content/browser/download/base_file.cc28
1 files changed, 23 insertions, 5 deletions
diff --git a/content/browser/download/base_file.cc b/content/browser/download/base_file.cc
index 9d55828f5e..b5ded45428 100644
--- a/content/browser/download/base_file.cc
+++ b/content/browser/download/base_file.cc
@@ -25,7 +25,7 @@ namespace content {
// This will initialize the entire array to zero.
const unsigned char BaseFile::kEmptySha256Hash[] = { 0 };
-BaseFile::BaseFile(const FilePath& full_path,
+BaseFile::BaseFile(const base::FilePath& full_path,
const GURL& source_url,
const GURL& referrer_url,
int64 received_bytes,
@@ -63,7 +63,7 @@ BaseFile::~BaseFile() {
}
DownloadInterruptReason BaseFile::Initialize(
- const FilePath& default_directory) {
+ const base::FilePath& default_directory) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
DCHECK(!detached_);
@@ -73,8 +73,8 @@ DownloadInterruptReason BaseFile::Initialize(
}
if (full_path_.empty()) {
- FilePath initial_directory(default_directory);
- FilePath temp_file;
+ base::FilePath initial_directory(default_directory);
+ base::FilePath temp_file;
if (initial_directory.empty()) {
initial_directory =
GetContentClient()->browser()->GetDefaultDownloadDirectory();
@@ -148,7 +148,7 @@ DownloadInterruptReason BaseFile::AppendDataToFile(const char* data,
return DOWNLOAD_INTERRUPT_REASON_NONE;
}
-DownloadInterruptReason BaseFile::Rename(const FilePath& new_path) {
+DownloadInterruptReason BaseFile::Rename(const base::FilePath& new_path) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
DownloadInterruptReason rename_result = DOWNLOAD_INTERRUPT_REASON_NONE;
@@ -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;
}