1use hexz_common::{Error, Result};
7use std::io::{Error as IoError, ErrorKind};
8use std::path::Path;
9
10#[derive(Debug, Clone)]
12pub struct RemoteArchiveInfo {
13 pub name: String,
15 pub size: u64,
17}
18
19pub trait RemoteTransport: Send + Sync {
21 fn list_archives(&self) -> Result<Vec<RemoteArchiveInfo>>;
23
24 fn upload(&self, local_path: &Path, remote_name: &str) -> Result<()>;
26
27 fn download(&self, remote_name: &str, local_path: &Path) -> Result<()>;
29
30 fn exists(&self, remote_name: &str) -> Result<bool>;
32}
33
34pub fn connect(url: &str) -> Result<Box<dyn RemoteTransport>> {
38 if url.starts_with("s3://") {
39 #[cfg(feature = "s3")]
40 {
41 let remote = crate::s3::remote::S3Remote::connect(url)?;
42 return Ok(Box::new(remote));
43 }
44 #[cfg(not(feature = "s3"))]
45 {
46 return Err(Error::Io(IoError::new(
47 ErrorKind::Unsupported,
48 "S3 support not compiled in (missing feature \"s3\")",
49 )));
50 }
51 }
52
53 if url.starts_with("http://") || url.starts_with("https://") {
54 return Err(Error::Io(IoError::new(
55 ErrorKind::Unsupported,
56 "HTTP remotes are not yet supported",
57 )));
58 }
59
60 Err(Error::Io(IoError::new(
61 ErrorKind::InvalidInput,
62 format!("Unsupported remote URL scheme: {url}"),
63 )))
64}