Skip to content

Commit

Permalink
feat(macos): add macos support for docker2fl
Browse files Browse the repository at this point in the history
  • Loading branch information
iwanbk committed Oct 30, 2024
1 parent 5b68426 commit ed20c5f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
10 changes: 9 additions & 1 deletion docker2fl/src/docker2fl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,17 @@ impl DockerImageToFlist {
}

pub async fn prepare(&mut self) -> Result<()> {
#[cfg(unix)]
#[cfg(all(unix, not(target_os = "macos")))]
let docker = Docker::connect_with_socket_defaults().context("failed to create docker")?;

#[cfg(target_os = "macos")]
let docker = Docker::connect_with_socket(
concat!(env!("HOME"), "/.docker/run/docker.sock"),
120,
bollard::API_DEFAULT_VERSION,
)
.context("failed to create docker")?;

let container_file =
Path::file_stem(self.docker_tmp_dir.path()).expect("failed to get directory name");
let container_name = container_file
Expand Down
32 changes: 17 additions & 15 deletions rfs/src/fungi/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,33 @@ use crate::store;

const ID_LEN: usize = 32;
const KEY_LEN: usize = 32;
const TYPE_MASK: u32 = nix::libc::S_IFMT;
const TYPE_MASK: u32 = nix::libc::S_IFMT as u32;

#[repr(u32)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum FileType {
Regular = nix::libc::S_IFREG,
Dir = nix::libc::S_IFDIR,
Link = nix::libc::S_IFLNK,
Block = nix::libc::S_IFBLK,
Char = nix::libc::S_IFCHR,
Socket = nix::libc::S_IFSOCK,
FIFO = nix::libc::S_IFIFO,
// we can't simply write `Regular = nix::libc::S_IFREG` because it is u32 in Linux but u16 in MacOS
Regular = nix::libc::S_IFREG as u32,
Dir = nix::libc::S_IFDIR as u32,
Link = nix::libc::S_IFLNK as u32,
Block = nix::libc::S_IFBLK as u32,
Char = nix::libc::S_IFCHR as u32,
Socket = nix::libc::S_IFSOCK as u32,
FIFO = nix::libc::S_IFIFO as u32,
Unknown = 0,
}

impl From<u32> for FileType {
fn from(value: u32) -> Self {
match value {
nix::libc::S_IFREG => Self::Regular,
nix::libc::S_IFDIR => Self::Dir,
nix::libc::S_IFLNK => Self::Link,
nix::libc::S_IFBLK => Self::Block,
nix::libc::S_IFCHR => Self::Char,
nix::libc::S_IFSOCK => Self::Socket,
nix::libc::S_IFIFO => Self::FIFO,
// we can't simply write `nix::libc::S_IFREG => Self::Regular` because it is u32 in Linux but u16 in MacOS
x if x == nix::libc::S_IFREG as u32 => Self::Regular,
x if x == nix::libc::S_IFDIR as u32 => Self::Dir,
x if x == nix::libc::S_IFLNK as u32 => Self::Link,
x if x == nix::libc::S_IFBLK as u32 => Self::Block,
x if x == nix::libc::S_IFCHR as u32 => Self::Char,
x if x == nix::libc::S_IFSOCK as u32 => Self::Socket,
x if x == nix::libc::S_IFIFO as u32 => Self::FIFO,
_ => Self::Unknown,
}
}
Expand Down

0 comments on commit ed20c5f

Please sign in to comment.