repository: Use location in log

This commit is contained in:
Alexander Weiss 2023-03-26 22:28:33 +02:00
parent 793162594b
commit 0998ddb836
10 changed files with 32 additions and 19 deletions

View File

@ -24,7 +24,7 @@ impl<BE: WriteBackend> CachedBackend<BE> {
}
impl<BE: WriteBackend> ReadBackend for CachedBackend<BE> {
fn location(&self) -> &str {
fn location(&self) -> String {
self.be.location()
}

View File

@ -28,7 +28,7 @@ impl ChooseBackend {
}
impl ReadBackend for ChooseBackend {
fn location(&self) -> &str {
fn location(&self) -> String {
match self {
Local(local) => local.location(),
Rest(rest) => rest.location(),

View File

@ -168,7 +168,7 @@ impl<R: ReadBackend, C: CryptoKey> DecryptReadBackend for DecryptBackend<R, C> {
}
impl<R: ReadBackend, C: CryptoKey> ReadBackend for DecryptBackend<R, C> {
fn location(&self) -> &str {
fn location(&self) -> String {
self.backend.location()
}

View File

@ -25,7 +25,7 @@ impl<BE: DecryptFullBackend> DecryptReadBackend for DryRunBackend<BE> {
}
impl<BE: DecryptFullBackend> ReadBackend for DryRunBackend<BE> {
fn location(&self) -> &str {
fn location(&self) -> String {
self.be.location()
}

View File

@ -16,7 +16,7 @@ impl<BE: WriteBackend> HotColdBackend<BE> {
}
impl<BE: WriteBackend> ReadBackend for HotColdBackend<BE> {
fn location(&self) -> &str {
fn location(&self) -> String {
self.be.location()
}

View File

@ -74,8 +74,10 @@ impl LocalBackend {
}
impl ReadBackend for LocalBackend {
fn location(&self) -> &str {
self.path.to_str().unwrap()
fn location(&self) -> String {
let mut location = "local:".to_string();
location.push_str(&self.path.to_string_lossy());
location
}
fn set_option(&mut self, option: &str, value: &str) -> Result<()> {

View File

@ -72,7 +72,7 @@ pub trait RepoFile: Serialize + DeserializeOwned + Sized + Send + Sync + 'static
}
pub trait ReadBackend: Clone + Send + Sync + 'static {
fn location(&self) -> &str;
fn location(&self) -> String;
fn set_option(&mut self, option: &str, value: &str) -> Result<()>;

View File

@ -22,6 +22,7 @@ impl Drop for ChildToKill {
#[derive(Clone)]
pub struct RcloneBackend {
rest: RestBackend,
url: String,
_child_data: Arc<ChildToKill>,
}
@ -80,7 +81,7 @@ impl RcloneBackend {
.take()
.ok_or_else(|| anyhow!("cannot get stdout of rclone"))?,
);
let url = loop {
let rest_url = loop {
if let Some(status) = child.try_wait()? {
bail!("rclone exited with {status}");
}
@ -110,24 +111,28 @@ impl RcloneBackend {
}
});
if !url.starts_with("http://") {
if !rest_url.starts_with("http://") {
bail!("url must start with http://! url: {url}");
}
let url = "http://".to_string() + user.as_str() + ":" + password.as_str() + "@" + &url[7..];
let rest_url =
"http://".to_string() + user.as_str() + ":" + password.as_str() + "@" + &rest_url[7..];
debug!("using REST backend with url {url}.");
let rest = RestBackend::new(&url)?;
let rest = RestBackend::new(&rest_url)?;
Ok(Self {
_child_data: Arc::new(ChildToKill(child)),
url: url.to_string(),
rest,
})
}
}
impl ReadBackend for RcloneBackend {
fn location(&self) -> &str {
self.rest.location()
fn location(&self) -> String {
let mut location = "rclone:".to_string();
location.push_str(&self.url);
location
}
fn set_option(&mut self, option: &str, value: &str) -> Result<()> {

View File

@ -101,8 +101,14 @@ impl RestBackend {
}
impl ReadBackend for RestBackend {
fn location(&self) -> &str {
self.url.as_str()
fn location(&self) -> String {
let mut location = "rest:".to_string();
let mut url = self.url.clone();
if url.password().is_some() {
url.set_password(Some("***")).unwrap();
}
location.push_str(url.as_str());
location
}
fn set_option(&mut self, option: &str, value: &str) -> Result<()> {

View File

@ -159,10 +159,10 @@ impl Repository {
for (opt, value) in &opts.options {
be.set_option(opt, value)?;
}
let mut name = opts.repository.as_ref().unwrap().clone();
if let Some(repo_hot) = &opts.repo_hot {
let mut name = be.location();
if let Some(be_hot) = &be_hot {
name.push('#');
name.push_str(repo_hot);
name.push_str(&be_hot.location());
}
Ok(Self {