Initial commit for desktop configuration. Broken now

This commit is contained in:
Igor Katson 2023-12-06 14:30:32 +00:00
parent dd355b0a74
commit a3475784e9
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
8 changed files with 304 additions and 57 deletions

View file

@ -68,18 +68,24 @@ fn dump_dht(dht: &Dht, filename: &Path, tempfile_name: &Path) -> anyhow::Result<
}
impl PersistentDht {
pub fn default_persistence_filename() -> anyhow::Result<PathBuf> {
let dirs = get_configuration_directory("dht")?;
let path = dirs.cache_dir().join("dht.json");
Ok(path)
}
pub async fn create(config: Option<PersistentDhtConfig>) -> anyhow::Result<Dht> {
let mut config = config.unwrap_or_default();
let config_filename = match config.config_filename.take() {
Some(config_filename) => config_filename,
None => {
let dirs = get_configuration_directory("dht")?;
let path = dirs.cache_dir().join("dht.json");
info!("will store DHT routing table to {:?} periodically", &path);
path
}
None => Self::default_persistence_filename()?,
};
info!(
"will store DHT routing table to {:?} periodically",
&config_filename
);
if let Some(parent) = config_filename.parent() {
std::fs::create_dir_all(parent)
.with_context(|| format!("error creating dir {:?}", &parent))?;