diff options
author | iseki <iseki@chromium.org> | 2014-09-02 23:10:23 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-03 06:13:46 +0000 |
commit | e5ce274558eaf7231b9294318cc1db2bd9c553ba (patch) | |
tree | 4bd39757df97bf6ee7fc3bd718f912a2911307ec /webkit | |
parent | a2465eaa9471d741000f957583cf81dd2c31ecd8 (diff) | |
download | chromium_src-e5ce274558eaf7231b9294318cc1db2bd9c553ba.zip chromium_src-e5ce274558eaf7231b9294318cc1db2bd9c553ba.tar.gz chromium_src-e5ce274558eaf7231b9294318cc1db2bd9c553ba.tar.bz2 |
Add truncation to StreamCopyOrMoveImpl and test case.
BUG=410126
TEST=content_unittests
Review URL: https://codereview.chromium.org/536453007
Cr-Commit-Position: refs/heads/master@{#293082}
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/browser/fileapi/copy_or_move_operation_delegate.cc | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/webkit/browser/fileapi/copy_or_move_operation_delegate.cc b/webkit/browser/fileapi/copy_or_move_operation_delegate.cc index 97de4f4..6bb089b 100644 --- a/webkit/browser/fileapi/copy_or_move_operation_delegate.cc +++ b/webkit/browser/fileapi/copy_or_move_operation_delegate.cc @@ -423,10 +423,12 @@ class StreamCopyOrMoveImpl // To use FileStreamWriter, we need to ensure the destination file exists. operation_runner_->CreateFile( - dest_url_, false /* exclusive */, + dest_url_, + true /* exclusive */, base::Bind(&StreamCopyOrMoveImpl::RunAfterCreateFileForDestination, weak_factory_.GetWeakPtr(), - callback, file_info.last_modified)); + callback, + file_info.last_modified)); } void RunAfterCreateFileForDestination( @@ -436,6 +438,33 @@ class StreamCopyOrMoveImpl if (cancel_requested_) error = base::File::FILE_ERROR_ABORT; + if (error != base::File::FILE_OK && + error != base::File::FILE_ERROR_EXISTS) { + callback.Run(error); + return; + } + + if (error == base::File::FILE_ERROR_EXISTS) { + operation_runner_->Truncate( + dest_url_, + 0 /* length */, + base::Bind(&StreamCopyOrMoveImpl::RunAfterTruncateForDestination, + weak_factory_.GetWeakPtr(), + callback, + last_modified)); + return; + } + RunAfterTruncateForDestination( + callback, last_modified, base::File::FILE_OK); + } + + void RunAfterTruncateForDestination( + const CopyOrMoveOperationDelegate::StatusCallback& callback, + const base::Time& last_modified, + base::File::Error error) { + if (cancel_requested_) + error = base::File::FILE_ERROR_ABORT; + if (error != base::File::FILE_OK) { callback.Run(error); return; |