Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions core/src/services/gcs/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,4 +538,18 @@ impl GcsCore {

self.send(req).await
}

pub async fn gcs_abort_resumable_upload(
&self,
location: &str,
) -> Result<Response<IncomingAsyncBody>> {
let mut req = Request::delete(location)
.header(CONTENT_LENGTH, 0)
.body(AsyncBody::Empty)
.map_err(new_request_build_error)?;

self.sign(&mut req).await?;

self.send(req).await
}
}
21 changes: 19 additions & 2 deletions core/src/services/gcs/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,26 @@ impl oio::Write for GcsWriter {
}
}

// TODO: we can cancel the upload by sending a DELETE request to the location
async fn abort(&mut self) -> Result<()> {
Ok(())
let location = if let Some(location) = &self.location {
location
} else {
return Ok(());
};

let resp = self.core.gcs_abort_resumable_upload(location).await?;

match resp.status().as_u16() {
// gcs returns 499 if the upload aborted successfully
// reference: https://cloud.google.com/storage/docs/performing-resumable-uploads#cancel-upload-json
499 => {
resp.into_body().consume().await?;
self.location = None;
self.buffer.clear();
Ok(())
}
_ => Err(parse_error(resp).await?),
}
}

async fn close(&mut self) -> Result<()> {
Expand Down