ex-cli 1.20.1

Command line tool to find, filter, sort and list files.
Documentation
use crate::error::MyResult;
use std::path::{Path, PathBuf};
#[cfg(unix)]
use uzers::{gid_t, uid_t};

pub struct ZipParent {
    path: PathBuf,
    depth: usize,
    #[cfg(unix)]
    uid: uid_t,
    #[cfg(unix)]
    gid: gid_t,
}

impl ZipParent {
    #[cfg(unix)]
    pub fn new(path: PathBuf, depth: usize) -> MyResult<Self> {
        let (uid, gid) = Self::get_owner(&path)?;
        let zip_parent = Self { path, depth, uid, gid };
        Ok(zip_parent)
    }

    #[cfg(unix)]
    fn get_owner(path: &Path) -> MyResult<(uid_t, gid_t)> {
        use std::fs;
        use std::os::unix::fs::MetadataExt;
        let metadata = fs::symlink_metadata(path).map_err(|e| (e, path))?;
        let uid = metadata.uid();
        let gid = metadata.gid();
        Ok((uid, gid))
    }

    #[cfg(not(unix))]
    pub fn new(path: PathBuf, depth: usize) -> MyResult<Self> {
        let zip_parent = Self { path, depth };
        Ok(zip_parent)
    }

    pub fn path(&self) -> &Path {
        &self.path
    }

    pub fn depth(&self) -> usize {
        self.depth
    }

    #[cfg(unix)]
    pub fn uid(&self) -> uid_t {
        self.uid
    }

    #[cfg(unix)]
    pub fn gid(&self) -> gid_t {
        self.gid
    }
}