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

Unified Diff: webkit/browser/fileapi/copy_or_move_operation_delegate.cc

Issue 536453007: Add truncation to StreamCopyOrMoveImpl and test case. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 | « content/browser/fileapi/file_system_operation_impl_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/browser/fileapi/copy_or_move_operation_delegate.cc
diff --git a/webkit/browser/fileapi/copy_or_move_operation_delegate.cc b/webkit/browser/fileapi/copy_or_move_operation_delegate.cc
index 97de4f406df6fe1a257951d76af1ec3c2bfc2ccd..6bb089b9540a7f61708fbbdcb4e557144ac402f9 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;
« no previous file with comments | « content/browser/fileapi/file_system_operation_impl_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698