use hexz_common::{Error, Result};
use std::io::{Error as IoError, ErrorKind};
use std::path::Path;
#[derive(Debug, Clone)]
pub struct RemoteArchiveInfo {
pub name: String,
pub size: u64,
}
pub trait RemoteTransport: Send + Sync {
fn list_archives(&self) -> Result<Vec<RemoteArchiveInfo>>;
fn upload(&self, local_path: &Path, remote_name: &str) -> Result<()>;
fn download(&self, remote_name: &str, local_path: &Path) -> Result<()>;
fn exists(&self, remote_name: &str) -> Result<bool>;
}
pub fn connect(url: &str) -> Result<Box<dyn RemoteTransport>> {
if url.starts_with("s3://") {
#[cfg(feature = "s3")]
{
let remote = crate::s3::remote::S3Remote::connect(url)?;
return Ok(Box::new(remote));
}
#[cfg(not(feature = "s3"))]
{
return Err(Error::Io(IoError::new(
ErrorKind::Unsupported,
"S3 support not compiled in (missing feature \"s3\")",
)));
}
}
if url.starts_with("http://") || url.starts_with("https://") {
return Err(Error::Io(IoError::new(
ErrorKind::Unsupported,
"HTTP remotes are not yet supported",
)));
}
Err(Error::Io(IoError::new(
ErrorKind::InvalidInput,
format!("Unsupported remote URL scheme: {url}"),
)))
}