remozipsy 0.2.0

Remote Zip Sync - sync remote zip to local fs
Documentation
use std::path::Path;

/// Helper function that can be used if you want to build your own
/// [`crate::FileSystem`]
pub fn calculate_local_unix_path(root: &Path, path: &Path) -> Option<String> {
    let local_unix_path = path.strip_prefix(root).ok()?.to_str()?;

    #[cfg(windows)]
    let local_unix_path = local_unix_path.replace(r#"\"#, "/");

    Some(local_unix_path.to_string())
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_calculate_local_unix_path_unix_root() {
        let root = Path::new("/home/user/project");
        let path = Path::new("/home/user/project/src/main.rs");
        assert_eq!(calculate_local_unix_path(root, path), Some("src/main.rs".to_string()));
    }

    #[cfg(windows)]
    #[test]
    fn test_calculate_local_unix_path_windows_root() {
        let root = Path::new("C:\\Users\\User\\Documents\\project");
        let path = Path::new("C:\\Users\\User\\Documents\\project\\src\\main.rs");
        assert_eq!(calculate_local_unix_path(root, path), Some("src/main.rs".to_string()));
    }

    #[test]
    fn test_calculate_local_unix_path_no_prefix() {
        let root = Path::new("/home/user/project");
        let path = Path::new("/other/home/user/project/src/main.rs");
        assert_eq!(calculate_local_unix_path(root, path), None);
    }
}