mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-27 15:57:09 +00:00
agent: replace match Result
with or_else
`or_else` is suitable for more complicated situations. We can use it to return Ok in Err handling. Signed-off-by: Tim Zhang <tim@hyper.sh>
This commit is contained in:
parent
64e4b2fa83
commit
8f8061da08
@ -612,24 +612,23 @@ pub fn ms_move_root(rootfs: &str) -> Result<bool> {
|
|||||||
MsFlags::MS_SLAVE | MsFlags::MS_REC,
|
MsFlags::MS_SLAVE | MsFlags::MS_REC,
|
||||||
None::<&str>,
|
None::<&str>,
|
||||||
)?;
|
)?;
|
||||||
match umount2(abs_mount_point, MntFlags::MNT_DETACH) {
|
umount2(abs_mount_point, MntFlags::MNT_DETACH).or_else(|e| {
|
||||||
Ok(_) => (),
|
if e.ne(&nix::Error::from(Errno::EINVAL)) && e.ne(&nix::Error::from(Errno::EPERM)) {
|
||||||
Err(e) => {
|
return Err(anyhow!(e));
|
||||||
if e.ne(&nix::Error::from(Errno::EINVAL)) && e.ne(&nix::Error::from(Errno::EPERM)) {
|
|
||||||
return Err(anyhow!(e));
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we have not privileges for umounting (e.g. rootless), then
|
|
||||||
// cover the path.
|
|
||||||
mount(
|
|
||||||
Some("tmpfs"),
|
|
||||||
abs_mount_point,
|
|
||||||
Some("tmpfs"),
|
|
||||||
MsFlags::empty(),
|
|
||||||
None::<&str>,
|
|
||||||
)?;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// If we have not privileges for umounting (e.g. rootless), then
|
||||||
|
// cover the path.
|
||||||
|
mount(
|
||||||
|
Some("tmpfs"),
|
||||||
|
abs_mount_point,
|
||||||
|
Some("tmpfs"),
|
||||||
|
MsFlags::empty(),
|
||||||
|
None::<&str>,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
})?;
|
||||||
}
|
}
|
||||||
|
|
||||||
mount(
|
mount(
|
||||||
|
@ -143,21 +143,15 @@ pub fn write_sync(fd: RawFd, msg_type: i32, data_str: &str) -> Result<()> {
|
|||||||
},
|
},
|
||||||
SYNC_DATA => {
|
SYNC_DATA => {
|
||||||
let length: i32 = data_str.len() as i32;
|
let length: i32 = data_str.len() as i32;
|
||||||
match write_count(fd, &length.to_be_bytes(), MSG_SIZE) {
|
write_count(fd, &length.to_be_bytes(), MSG_SIZE).or_else(|e| {
|
||||||
Ok(_count) => (),
|
unistd::close(fd)?;
|
||||||
Err(e) => {
|
Err(anyhow!(e).context("error in send message to process"))
|
||||||
unistd::close(fd)?;
|
})?;
|
||||||
return Err(anyhow!(e).context("error in send message to process"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
match write_count(fd, data_str.as_bytes(), data_str.len()) {
|
write_count(fd, data_str.as_bytes(), data_str.len()).or_else(|e| {
|
||||||
Ok(_count) => (),
|
unistd::close(fd)?;
|
||||||
Err(e) => {
|
Err(anyhow!(e).context("error in send message to process"))
|
||||||
unistd::close(fd)?;
|
})?;
|
||||||
return Err(anyhow!(e).context("error in send message to process"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => (),
|
_ => (),
|
||||||
|
Loading…
Reference in New Issue
Block a user