Merge pull request #1478 from lifupan/fix_device

rustjail: fix the issue of bind mount device file from guest
This commit is contained in:
Fupan Li 2021-03-08 09:55:00 +08:00 committed by GitHub
commit f6630ddd49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -736,10 +736,10 @@ fn mount_from(
let src = if m.r#type.as_str() == "bind" { let src = if m.r#type.as_str() == "bind" {
let src = fs::canonicalize(m.source.as_str())?; let src = fs::canonicalize(m.source.as_str())?;
let dir = if src.is_file() { let dir = if src.is_dir() {
Path::new(&dest).parent().unwrap()
} else {
Path::new(&dest) Path::new(&dest)
} else {
Path::new(&dest).parent().unwrap()
}; };
let _ = fs::create_dir_all(&dir).map_err(|e| { let _ = fs::create_dir_all(&dir).map_err(|e| {
@ -752,7 +752,7 @@ fn mount_from(
}); });
// make sure file exists so we can bind over it // make sure file exists so we can bind over it
if src.is_file() { if !src.is_dir() {
let _ = OpenOptions::new().create(true).write(true).open(&dest); let _ = OpenOptions::new().create(true).write(true).open(&dest);
} }
src.to_str().unwrap().to_string() src.to_str().unwrap().to_string()