radicle: Move some functions to `Home` type

Certain functions in `Profile` did not need to be in there and could be
moved in the more basic `Home` type.
This commit is contained in:
cloudhead 2023-11-03 17:06:33 +01:00
parent d15534df97
commit a70664368e
No known key found for this signature in database
5 changed files with 72 additions and 20 deletions

View File

@ -106,7 +106,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
term::print(profile.did());
}
Show::Home => {
term::print(profile.home().display());
term::print(profile.home().path().display());
}
Show::Config => {
term::print(profile.home.config().display());
@ -171,7 +171,7 @@ fn all(profile: &Profile) -> anyhow::Result<()> {
let home = profile.home();
table.push([
term::format::style("Home").into(),
term::format::tertiary(home.display()).into(),
term::format::tertiary(home.path().display()).into(),
]);
let config_path = profile.home.config();

View File

@ -60,7 +60,7 @@ pub async fn run(options: Options) -> anyhow::Result<()> {
let profile = Profile::load()?;
let request_id = RequestId::new();
tracing::info!("using radicle home at {}", profile.home().display());
tracing::info!("using radicle home at {}", profile.home().path().display());
let app =
router(options, profile)?

View File

@ -329,9 +329,9 @@ impl Node<MockSigner> {
let home = Home::new(home).unwrap();
let signer = MockSigner::default();
let storage = Storage::open(home.storage()).unwrap();
let addresses = Book::memory().unwrap();
let tracking = tracking::Config::<tracking::Write>::memory().unwrap();
let routing = routing::Table::memory().unwrap();
let addresses = home.addresses_mut().unwrap();
let tracking = home.tracking_mut().unwrap();
let routing = home.routing_mut().unwrap();
Self {
id: *signer.public_key(),

View File

@ -7,7 +7,7 @@ fn main() -> anyhow::Result<()> {
"fingerprint: {}",
radicle::crypto::ssh::fmt::fingerprint(profile.id())
);
println!("home: {}", profile.home().display());
println!("home: {}", profile.home().path().display());
Ok(())
}

View File

@ -259,30 +259,34 @@ impl Profile {
Ok(addresses)
}
/// Get radicle home.
pub fn home(&self) -> &Home {
&self.home
}
/// Return a multi-source store for aliases.
pub fn aliases(&self) -> Aliases {
let tracking = self.tracking().ok();
let addresses = self.addresses().ok();
let tracking = self.home.tracking().ok();
let addresses = self.home.addresses().ok();
Aliases {
tracking,
addresses,
}
}
}
/// Return the path to the keys folder.
pub fn keys(&self) -> PathBuf {
self.home.keys()
impl std::ops::Deref for Profile {
type Target = Home;
fn deref(&self) -> &Self::Target {
&self.home
}
}
/// Get the profile home directory.
pub fn home(&self) -> &Path {
self.home.path()
}
/// Get the path to the radicle node socket.
pub fn socket(&self) -> PathBuf {
self.home.socket()
impl std::ops::DerefMut for Profile {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.home
}
}
@ -387,6 +391,54 @@ impl Home {
.map(PathBuf::from)
.unwrap_or_else(|| self.node().join(node::DEFAULT_SOCKET_NAME))
}
/// Return a read-only handle to the tracking configuration of the node.
pub fn tracking(&self) -> Result<tracking::store::ConfigReader, tracking::store::Error> {
let path = self.node().join(node::TRACKING_DB_FILE);
let config = tracking::store::Config::reader(path)?;
Ok(config)
}
/// Return a read-write handle to the tracking configuration of the node.
pub fn tracking_mut(&self) -> Result<tracking::store::ConfigWriter, tracking::store::Error> {
let path = self.node().join(node::TRACKING_DB_FILE);
let config = tracking::store::Config::open(path)?;
Ok(config)
}
/// Return a read-only handle to the routing database of the node.
pub fn routing(&self) -> Result<routing::Table, routing::Error> {
let path = self.node().join(node::ROUTING_DB_FILE);
let router = routing::Table::reader(path)?;
Ok(router)
}
/// Return a read-write handle to the routing database of the node.
pub fn routing_mut(&self) -> Result<routing::Table, routing::Error> {
let path = self.node().join(node::ROUTING_DB_FILE);
let router = routing::Table::open(path)?;
Ok(router)
}
/// Return a handle to a read-only addresses database of the node.
pub fn addresses(&self) -> Result<address::Book, address::Error> {
let path = self.node().join(node::ADDRESS_DB_FILE);
let addresses = address::Book::reader(path)?;
Ok(addresses)
}
/// Return a handle to the addresses database of the node.
pub fn addresses_mut(&self) -> Result<address::Book, address::Error> {
let path = self.node().join(node::ADDRESS_DB_FILE);
let addresses = address::Book::open(path)?;
Ok(addresses)
}
}
#[cfg(test)]