use std::process::{Command, Stdio};
use tokio_process::CommandExt;
use crate::common::*;
pub(crate) async fn prepare_as_destination_helper(
ctx: Context,
s3_url: Url,
if_exists: IfExists,
) -> Result<()> {
if if_exists == IfExists::Overwrite {
debug!(ctx.log(), "deleting existing {}", s3_url);
if !s3_url.path().ends_with('/') {
return Err(format_err!(
"can only write to s3:// URL ending in '/', got {}",
s3_url,
));
}
let status = Command::new("aws")
.args(&["s3", "rm", "--recursive", s3_url.as_str()])
.stdout(Stdio::null())
.status_async()
.context("error running `aws s3`")?;
if !status.compat().await?.success() {
warn!(
ctx.log(),
"can't delete contents of {}, possibly because it doesn't exist",
s3_url,
);
}
Ok(())
} else {
Err(format_err!(
"must specify `overwrite` for {} destination",
s3_url,
))
}
}