Skip to content

Commit fa5d60f

Browse files
committed
Add more context to set_current_dir errors
1 parent e627cf0 commit fa5d60f

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

crates/container/src/lib.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-FileCopyrightText: Copyright © 2020-2024 Serpent OS Developers
22
//
33
// SPDX-License-Identifier: MPL-2.0
4-
use std::env::set_current_dir;
4+
55
use std::io;
66
use std::os::fd::AsRawFd;
77
use std::path::{Path, PathBuf};
@@ -358,6 +358,26 @@ fn add_mount<T: AsRef<Path>>(
358358
Ok(())
359359
}
360360

361+
fn set_current_dir(path: impl AsRef<Path>) -> io::Result<()> {
362+
#[derive(Debug, Error)]
363+
#[error("failed to set current directory to `{}`", path.display())]
364+
struct SetCurrentDirError {
365+
source: io::Error,
366+
path: PathBuf,
367+
}
368+
369+
let path = path.as_ref();
370+
std::env::set_current_dir(path).map_err(|source| {
371+
io::Error::new(
372+
source.kind(),
373+
SetCurrentDirError {
374+
source,
375+
path: path.to_owned(),
376+
},
377+
)
378+
})
379+
}
380+
361381
fn ignore_sigint() -> Result<(), nix::Error> {
362382
let action = SigAction::new(SigHandler::SigIgn, SaFlags::empty(), SigSet::empty());
363383
unsafe { sigaction(Signal::SIGINT, &action)? };

0 commit comments

Comments
 (0)