refactor: put the dry-run and quiet checks on Ctx
This commit is contained in:
@@ -11,11 +11,10 @@ use self::server::{Database, wait_until_ready, when_ready};
|
||||
use self::shape::{Dump, HEADER_LEN, Kind};
|
||||
use crate::cli::Format;
|
||||
use crate::cmd::{
|
||||
Cmd, Cp, CreateDb, DropDb, Gunzip, Gzip, Head, PgDump, PgDumpAll, PgRestore, Psql, Rm, Start,
|
||||
Stop, Up,
|
||||
Cmd, Cp, CreateDb, DropDb, Gunzip, Gzip, Head, PgDump, PgDumpAll, PgRestore, Psql, Rm,
|
||||
};
|
||||
use crate::ctx::Ctx;
|
||||
use crate::fsops::{create_private_new, remove_file, rename, suffixed};
|
||||
use crate::fsops::{create_private_new, suffixed};
|
||||
use crate::output::{note, warning};
|
||||
|
||||
// unique per run: docker cp will not copy a directory over an existing path, and
|
||||
@@ -136,7 +135,7 @@ pub fn import(ctx: &Ctx, file: &Path) -> Result<()> {
|
||||
}
|
||||
|
||||
note!(ctx, "stopping all containers");
|
||||
Stop { quiet: ctx.quiet }.run(ctx)?;
|
||||
ctx.compose().stop().run(ctx)?;
|
||||
|
||||
// everything from here runs with the project down, so an error leaves it
|
||||
// that way and the user has no reason to guess as much
|
||||
@@ -159,11 +158,7 @@ fn local_path_for_docker(file: &Path) -> Result<()> {
|
||||
|
||||
fn imported(ctx: &Ctx, db: &Database, dump: &Dump, file: &Path) -> Result<()> {
|
||||
note!(ctx, "starting db container");
|
||||
Start {
|
||||
service: &db.service,
|
||||
quiet: ctx.quiet,
|
||||
}
|
||||
.run(ctx)?;
|
||||
ctx.compose().start(&db.service).run(ctx)?;
|
||||
|
||||
let remote = remote_dump();
|
||||
|
||||
@@ -229,8 +224,8 @@ fn imported(ctx: &Ctx, db: &Database, dump: &Dump, file: &Path) -> Result<()> {
|
||||
restored?;
|
||||
|
||||
note!(ctx, "restarting containers");
|
||||
Stop { quiet: ctx.quiet }.run(ctx)?;
|
||||
Up { quiet: ctx.quiet }.run(ctx)?;
|
||||
ctx.compose().stop().run(ctx)?;
|
||||
ctx.compose().up().run(ctx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -337,11 +332,11 @@ pub fn dump(ctx: &Ctx, file: &Path, format: Format, gzip: bool) -> Result<()> {
|
||||
};
|
||||
|
||||
if let Err(e) = dumped {
|
||||
let _ = remove_file(ctx, &partial);
|
||||
let _ = ctx.fs().remove_file(&partial);
|
||||
return Err(e);
|
||||
}
|
||||
|
||||
rename(ctx, &partial, file)?;
|
||||
ctx.fs().rename(&partial, file)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user