Skip to content

Commit

Permalink
feat(catalog): try stripping $HOME when displaying catalog dirpath
Browse files Browse the repository at this point in the history
  • Loading branch information
graelo committed Nov 5, 2022
1 parent 2237f8c commit 41a85f6
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/management/catalog.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! Catalog of all backups.
use std::iter;
use std::borrow::Cow;
use std::ops::RangeInclusive;
use std::path::{Path, PathBuf};
use std::{env, iter};

use async_std::stream::StreamExt;
use async_std::{fs, task};
Expand Down Expand Up @@ -213,7 +214,19 @@ impl Catalog {

async fn print_table(&self, details_flag: bool) {
println!("Strategy: {}", &self.strategy);
println!("Location: `{}`\n", self.dirpath.to_string_lossy());

// Try to strip the HOME prefix from self.dirpath, otherwise return self.dirpath.
let location: Cow<Path> = {
if let Some(remainder) = env::var("HOME")
.ok()
.and_then(|home_dir| self.dirpath.strip_prefix(home_dir).ok())
{
Cow::Owned(PathBuf::from("$HOME").join(remainder))
} else {
Cow::Borrowed(&self.dirpath)
}
};
println!("Location: `{}`\n", location.to_string_lossy());

let Plan {
purgeable,
Expand Down

0 comments on commit 41a85f6

Please sign in to comment.