Skip to content

Commit

Permalink
Rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
simonsan committed Oct 23, 2024
1 parent 996a10f commit 6ee6ef8
Show file tree
Hide file tree
Showing 59 changed files with 2,468 additions and 1,705 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ rclone = ["rest", "dep:rand", "dep:semver"]
rustic_core = { workspace = true }

# errors
anyhow = "1.0.89"
displaydoc = "0.2.5"
thiserror = "1.0.64"

Expand Down
26 changes: 17 additions & 9 deletions crates/backend/src/choose.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
//! This module contains [`BackendOptions`] and helpers to choose a backend from a given url.
use anyhow::{anyhow, Result};
use derive_setters::Setters;
use std::{collections::HashMap, sync::Arc};
use strum_macros::{Display, EnumString};

#[allow(unused_imports)]
use rustic_core::{RepositoryBackends, WriteBackend};
use rustic_core::{RepositoryBackends, RusticResult, WriteBackend};

use crate::{
error::BackendAccessErrorKind,
local::LocalBackend,
util::{location_to_type_and_path, BackendLocation},
};
Expand All @@ -25,6 +23,13 @@ use crate::rest::RestBackend;
#[cfg(feature = "clap")]
use clap::ValueHint;

/// [`ChooseBackendErrorKind`] describes the errors that can be returned by the choose backend
#[derive(thiserror::Error, Debug, displaydoc::Display)]
#[non_exhaustive]
pub enum ChooseBackendErrorKind {}

pub(crate) type ChooseBackendResult<T> = Result<T, ChooseBackendErrorKind>;

/// Options for a backend.
#[cfg_attr(feature = "clap", derive(clap::Parser))]
#[cfg_attr(feature = "merge", derive(conflate::Merge))]
Expand Down Expand Up @@ -75,12 +80,12 @@ impl BackendOptions {
/// # Returns
///
/// The backends for the repository.
pub fn to_backends(&self) -> Result<RepositoryBackends> {
pub fn to_backends(&self) -> RusticResult<RepositoryBackends> {
let mut options = self.options.clone();
options.extend(self.options_cold.clone());
let be = self
.get_backend(self.repository.as_ref(), options)?
.ok_or_else(|| anyhow!("No repository given."))?;
.ok_or_else(|| Err("No repository given.".to_string()).into())?;
let mut options = self.options.clone();
options.extend(self.options_hot.clone());
let be_hot = self.get_backend(self.repo_hot.as_ref(), options)?;
Expand Down Expand Up @@ -108,12 +113,15 @@ impl BackendOptions {
&self,
repo_string: Option<&String>,
options: HashMap<String, String>,
) -> Result<Option<Arc<dyn WriteBackend>>> {
) -> BackendResult<Option<Arc<dyn WriteBackend>>> {
repo_string
.map(|string| {
let (be_type, location) = location_to_type_and_path(string)?;
be_type.to_backend(location, options.into()).map_err(|err| {
BackendAccessErrorKind::BackendLoadError(be_type.to_string(), err).into()
BackendErrorKind::BackendLoadError {
name: be_type,
source: err,
}
})
})
.transpose()
Expand All @@ -138,7 +146,7 @@ pub trait BackendChoice {
&self,
location: BackendLocation,
options: Option<HashMap<String, String>>,
) -> Result<Arc<dyn WriteBackend>>;
) -> RusticResult<Arc<dyn WriteBackend>>;
}

/// The supported backend types.
Expand Down Expand Up @@ -176,7 +184,7 @@ impl BackendChoice for SupportedBackend {
&self,
location: BackendLocation,
options: Option<HashMap<String, String>>,
) -> Result<Arc<dyn WriteBackend>> {
) -> RusticResult<Arc<dyn WriteBackend>> {
let options = options.unwrap_or_default();

Ok(match self {
Expand Down
134 changes: 0 additions & 134 deletions crates/backend/src/error.rs

This file was deleted.

21 changes: 11 additions & 10 deletions crates/backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,22 @@ This crate exposes a few features for controlling dependency usage:
*/

pub mod choose;
/// Error types for the backend.
pub mod error;
/// Local backend for Rustic.
pub mod local;
/// Utility functions for the backend.
pub mod util;

/// `OpenDAL` backend for Rustic.
#[cfg(feature = "opendal")]
pub mod opendal;

/// `Rclone` backend for Rustic.
#[cfg(feature = "rclone")]
pub mod rclone;

/// REST backend for Rustic.
#[cfg(feature = "rest")]
pub mod rest;
/// Utility functions for the backend.
pub mod util;

// rustic_backend Public API
pub use crate::{
choose::{BackendOptions, SupportedBackend},
local::LocalBackend,
};

#[cfg(feature = "opendal")]
pub use crate::opendal::OpenDALBackend;
Expand All @@ -83,3 +78,9 @@ pub use crate::rclone::RcloneBackend;

#[cfg(feature = "rest")]
pub use crate::rest::RestBackend;

// rustic_backend Public API
pub use crate::{
choose::{BackendOptions, SupportedBackend},
local::LocalBackend,
};
Loading

0 comments on commit 6ee6ef8

Please sign in to comment.