Remove LogsDir in favor of just path::PathBuf

This commit is contained in:
Kiril Videlov 2024-01-31 15:42:37 +01:00 committed by Kiril Videlov
parent bfbfaacdd0
commit 3e1a77e83a
4 changed files with 22 additions and 68 deletions

View File

@ -18,7 +18,6 @@ pub mod keys;
pub mod lock; pub mod lock;
pub mod logs; pub mod logs;
pub mod menu; pub mod menu;
pub mod paths;
pub mod project_repository; pub mod project_repository;
pub mod projects; pub mod projects;
pub mod reader; pub mod reader;

View File

@ -5,12 +5,13 @@ use tracing::{metadata::LevelFilter, subscriber::set_global_default};
use tracing_appender::rolling::{RollingFileAppender, Rotation}; use tracing_appender::rolling::{RollingFileAppender, Rotation};
use tracing_subscriber::{fmt::format::FmtSpan, layer::SubscriberExt, Layer}; use tracing_subscriber::{fmt::format::FmtSpan, layer::SubscriberExt, Layer};
use crate::{paths::LogsDir, sentry}; use crate::sentry;
pub fn init(app_handle: &AppHandle) { pub fn init(app_handle: &AppHandle) {
let logs_dir = LogsDir::try_from(app_handle) let logs_dir = app_handle
.expect("failed to get logs dir") .path_resolver()
.to_path_buf(); .app_log_dir()
.expect("failed to get logs dir");
fs::create_dir_all(&logs_dir).expect("failed to create logs dir"); fs::create_dir_all(&logs_dir).expect("failed to create logs dir");
let file_appender = RollingFileAppender::builder() let file_appender = RollingFileAppender::builder()

View File

@ -1,42 +0,0 @@
use std::path;
use anyhow::Context;
use tauri::AppHandle;
pub struct LogsDir(path::PathBuf);
impl LogsDir {
pub fn to_path_buf(&self) -> path::PathBuf {
self.0.clone()
}
}
impl TryFrom<&AppHandle> for LogsDir {
type Error = anyhow::Error;
fn try_from(app_handle: &AppHandle) -> Result<Self, Self::Error> {
app_handle
.path_resolver()
.app_log_dir()
.map(Self)
.context("failed to get app log dir")
}
}
impl From<&path::PathBuf> for LogsDir {
fn from(value: &path::PathBuf) -> Self {
Self::from(value.clone())
}
}
impl From<path::PathBuf> for LogsDir {
fn from(value: path::PathBuf) -> Self {
Self(value)
}
}
impl From<LogsDir> for path::PathBuf {
fn from(logs_dir: LogsDir) -> Self {
logs_dir.0
}
}

View File

@ -2,16 +2,13 @@ use std::path;
use tauri::AppHandle; use tauri::AppHandle;
use crate::{ use crate::projects::{self, ProjectId};
paths::LogsDir,
projects::{self, ProjectId},
};
use super::Zipper; use super::Zipper;
pub struct Controller { pub struct Controller {
local_data_dir: path::PathBuf, local_data_dir: path::PathBuf,
logs_dir: LogsDir, logs_dir: path::PathBuf,
zipper: Zipper, zipper: Zipper,
projects_controller: projects::Controller, projects_controller: projects::Controller,
} }
@ -20,19 +17,20 @@ impl TryFrom<&AppHandle> for Controller {
type Error = anyhow::Error; type Error = anyhow::Error;
fn try_from(value: &AppHandle) -> Result<Self, Self::Error> { fn try_from(value: &AppHandle) -> Result<Self, Self::Error> {
let local_data_dir = value.path_resolver().app_data_dir(); let local_data_dir = value
match local_data_dir { .path_resolver()
Some(local_data_dir) => { .app_data_dir()
let logs_dir = LogsDir::try_from(value)?; .ok_or_else(|| anyhow::anyhow!("failed to get local data dir"))?;
Ok(Self { let logs_dir = value
local_data_dir, .path_resolver()
logs_dir, .app_log_dir()
zipper: Zipper::try_from(value)?, .ok_or_else(|| anyhow::anyhow!("failed to get logs dir"))?;
projects_controller: projects::Controller::try_from(value)?, Ok(Self {
}) local_data_dir,
} logs_dir,
None => Err(anyhow::anyhow!("failed to get app data dir")), zipper: Zipper::try_from(value)?,
} projects_controller: projects::Controller::try_from(value)?,
})
} }
} }
@ -54,9 +52,7 @@ impl Controller {
} }
pub fn logs_archive(&self) -> Result<path::PathBuf, LogsArchiveError> { pub fn logs_archive(&self) -> Result<path::PathBuf, LogsArchiveError> {
self.zipper self.zipper.zip(&self.logs_dir).map_err(Into::into)
.zip(self.logs_dir.to_path_buf())
.map_err(Into::into)
} }
} }