Skip to content

Commit

Permalink
Merge pull request #16 from rumpl/fix-mount-dest
Browse files Browse the repository at this point in the history
Create destination directory
  • Loading branch information
hydai committed Oct 20, 2022
2 parents 6a43b03 + f445981 commit d10cb77
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions crates/containerd-shim-wasm/src/sandbox/shim.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::HashMap;
use std::env::current_dir;
use std::fs::{self, File};
use std::fs::{canonicalize, create_dir_all, OpenOptions};
use std::ops::Not;
use std::os::unix::io::AsRawFd;
use std::path::Path;
Expand Down Expand Up @@ -1359,12 +1360,33 @@ where
continue;
}

let os_source = m.source().as_ref().unwrap().clone().into_os_string();
let source = os_source.to_string_lossy();
let dest = m.destination();
let source = m.source().as_ref().unwrap();
let src = canonicalize(source).unwrap();

let flags = parse_mount(m);
let dir = if src.is_file() {
Path::new(&dest).parent().unwrap()
} else {
Path::new(&dest)
};

create_dir_all(dir).unwrap();

if src.is_file() {
OpenOptions::new()
.create(true)
.write(true)
.open(&dest)
.unwrap();
}

mount::<str, Path, str, str>(Some(&source), m.destination(), None, flags, None)?;
mount::<str, Path, str, str>(
Some(&src.to_string_lossy()),
dest,
None,
parse_mount(m),
None,
)?;
}
}

Expand Down

0 comments on commit d10cb77

Please sign in to comment.