mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-29 08:47:56 +00:00
agent: fix the issue of creating the dns file
We should make sure the dns's source file's parent directory exist, otherwise, it would failed to create the file directly. Signed-off-by: Fupan Li <fupan.lfp@antgroup.com>
This commit is contained in:
parent
139ad8e95f
commit
32ebe1895b
@ -7,6 +7,7 @@ use anyhow::{anyhow, Result};
|
|||||||
use nix::mount::{self, MsFlags};
|
use nix::mount::{self, MsFlags};
|
||||||
use slog::Logger;
|
use slog::Logger;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::path;
|
||||||
|
|
||||||
const KATA_GUEST_SANDBOX_DNS_FILE: &str = "/run/kata-containers/sandbox/resolv.conf";
|
const KATA_GUEST_SANDBOX_DNS_FILE: &str = "/run/kata-containers/sandbox/resolv.conf";
|
||||||
const GUEST_DNS_FILE: &str = "/etc/resolv.conf";
|
const GUEST_DNS_FILE: &str = "/etc/resolv.conf";
|
||||||
@ -64,6 +65,12 @@ fn do_setup_guest_dns(logger: Logger, dns_list: Vec<String>, src: &str, dst: &st
|
|||||||
.map(|x| x.trim())
|
.map(|x| x.trim())
|
||||||
.collect::<Vec<&str>>()
|
.collect::<Vec<&str>>()
|
||||||
.join("\n");
|
.join("\n");
|
||||||
|
|
||||||
|
// make sure the src file's parent path exist.
|
||||||
|
let file_path = path::Path::new(src);
|
||||||
|
if let Some(p) = file_path.parent() {
|
||||||
|
fs::create_dir_all(p)?;
|
||||||
|
}
|
||||||
fs::write(src, content)?;
|
fs::write(src, content)?;
|
||||||
|
|
||||||
// bind mount to /etc/resolv.conf
|
// bind mount to /etc/resolv.conf
|
||||||
|
Loading…
Reference in New Issue
Block a user