Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(macos): add macos support for docker2fl #82

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ jobs:
- uses: clechasseur/rs-fmt-check@v2

test:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- name: Get Dependencies
run: |
sudo apt-get update
sudo apt-get install capnproto
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand Down
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
Loading