From c346645fc96abf9831ce723bb56e26f95e3c5b45 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Fri, 1 May 2015 16:24:21 +0200 Subject: [PATCH] fix(API): let delegate forget uploaded urls When uploading using the resumable protocol, we are now telling the delegate to forget the previously stored URL after successful upload. Previously it would have tried to return such a URL and thus made the system retry uploading a file that was already uploaded. Fixes #85 [skip ci] --- src/mako/api/lib/mbuild.mako | 3 ++- src/rust/api/cmn.rs | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/mako/api/lib/mbuild.mako b/src/mako/api/lib/mbuild.mako index 94abe2106b..b6af9cfd9a 100644 --- a/src/mako/api/lib/mbuild.mako +++ b/src/mako/api/lib/mbuild.mako @@ -800,7 +800,7 @@ else { let upload_result = { let url_str = &res.headers.get::().expect("Location header is part of protocol").0; if upload_url_from_server { - dlg.store_upload_url(url_str); + dlg.store_upload_url(Some(url_str)); } cmn::ResumableUploadHelper { @@ -832,6 +832,7 @@ else { res = upload_result; if !res.status.is_success() { ## delegate was called in upload() already - don't tell him again + dlg.store_upload_url(None); ${delegate_finish}(false); return Err(Error::Failure(res)) } diff --git a/src/rust/api/cmn.rs b/src/rust/api/cmn.rs index cd013bd649..44e55348f2 100644 --- a/src/rust/api/cmn.rs +++ b/src/rust/api/cmn.rs @@ -171,7 +171,10 @@ pub trait Delegate { /// Called after we have retrieved a new upload URL for a resumable upload to store it /// in case we fail or cancel. That way, we can attempt to resume the upload later, /// see `upload_url()`. - fn store_upload_url(&mut self, url: &str) { + /// It will also be called with None after a successful upload, which allows the delegate + /// to forget the URL. That way, we will not attempt to resume an upload that has already + /// finished. + fn store_upload_url(&mut self, url: Option<&str>) { let _ = url; }