Skip to main content

kernel_builder/
consts.rs

1use std::path::{Path, PathBuf};
2
3pub const KERNEL_PATTERN: &str = "linux-";
4pub const LINUX_SYMLINK: &str = "linux";
5pub const CONFIG_FILENAME: &str = ".config";
6pub const KERNEL_IMAGE_PATH: &str = "arch/x86/boot/bzImage";
7pub const MAKE_COMMAND: &str = "make";
8pub const DEFAULT_LOG_LEVEL: &str = "info";
9
10#[cfg(feature = "dracut")]
11pub const DRACUT_COMMAND: &str = "dracut";
12
13#[derive(Clone, Debug)]
14pub struct KernelPaths {
15    pub kernel_image: PathBuf,
16    pub initramfs: Option<PathBuf>,
17    pub kernel_config: PathBuf,
18    pub kernel_src: PathBuf,
19    pub linux_symlink: PathBuf,
20}
21
22impl KernelPaths {
23    #[must_use]
24    pub fn new(
25        kernel_file_path: PathBuf,
26        initramfs_file_path: Option<PathBuf>,
27        kernel_config_file_path: PathBuf,
28        kernel_src: PathBuf,
29    ) -> Self {
30        Self {
31            kernel_image: kernel_file_path,
32            initramfs: initramfs_file_path,
33            kernel_config: kernel_config_file_path,
34            kernel_src: kernel_src.clone(),
35            linux_symlink: kernel_src.join(LINUX_SYMLINK),
36        }
37    }
38
39    #[must_use]
40    pub fn backup_path(&self, original: &Path, suffix: &str) -> PathBuf {
41        let filename = original.file_name().map_or_else(
42            || suffix.to_string(),
43            |n: &std::ffi::OsStr| format!("{}{}", n.to_string_lossy(), suffix),
44        );
45        original.with_file_name(filename)
46    }
47}