Skip to content
This repository was archived by the owner on Jan 9, 2020. It is now read-only.

Commit 0c1d7ea

Browse files
author
Vishvananda Ishaya Abrams
committed
remove dir on failed create
1 parent da3c8ef commit 0c1d7ea

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/main.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -499,15 +499,6 @@ fn cmd_create(id: &str, state_dir: &str, matches: &ArgMatches) -> Result<()> {
499499
chdir(&*bundle).chain_err(
500500
|| format!("failed to chdir to {}", bundle),
501501
)?;
502-
let spec = Spec::load(CONFIG).chain_err(
503-
|| format!("failed to load {}", CONFIG),
504-
)?;
505-
506-
let rootfs = canonicalize(&spec.root.path)
507-
.chain_err(|| format!{"failed to find root path {}", &spec.root.path})?
508-
.to_string_lossy()
509-
.into_owned();
510-
511502
let dir = instance_dir(id, state_dir);
512503
debug!("creating state dir {}", &dir);
513504
if let Err(e) = create_dir(&dir) {
@@ -517,6 +508,23 @@ fn cmd_create(id: &str, state_dir: &str, matches: &ArgMatches) -> Result<()> {
517508
}
518509
bail!("Container with id {} already exists", id);
519510
}
511+
if let Err(e) = finish_create(id, &dir, matches) {
512+
let _ = remove_dir_all(&dir);
513+
Err(e)
514+
} else {
515+
Ok(())
516+
}
517+
}
518+
519+
fn finish_create(id: &str, dir: &str, matches: &ArgMatches) -> Result<()> {
520+
let spec = Spec::load(CONFIG).chain_err(
521+
|| format!("failed to load {}", CONFIG),
522+
)?;
523+
524+
let rootfs = canonicalize(&spec.root.path)
525+
.chain_err(|| format!{"failed to find root path {}", &spec.root.path})?
526+
.to_string_lossy()
527+
.into_owned();
520528

521529
chdir(&*dir).chain_err(
522530
|| format!("failed to chdir to {}", &dir),

0 commit comments

Comments
 (0)