feat(all): Add loging

This commit is contained in:
Black_Raven committed 2026-03-30 13:58:33 +03:00
1 parent 25080e3cca
commit dfa7c463ac
10 files changed
+108 -45

No files matched your search

-2
View File
@@ -1,6 +1,4 @@
use super::*;
use crate::rclone_install::RcloneApp;
use serde_json::Value;
/// Проверить разницу между двумя директориями
pub fn diff(app: &RcloneApp, source: &str, dest: &str) -> Result<Vec<String>, String> {
+19
View File
@@ -0,0 +1,19 @@
use super::*;
impl FileInfo {
pub fn format_size(&self) -> String {
let bytes = self.size;
if bytes < 1024 {
format!("{} B", bytes)
} else if bytes < 1024 * 1024 {
format!("{:.1} KB", bytes as f64 / 1024.0)
} else if bytes < 1024 * 1024 * 1024 {
format!("{:.1} MB", bytes as f64 / (1024.0 * 1024.0))
} else {
format!("{:.2} GB", bytes as f64 / (1024.0 * 1024.0 * 1024.0))
}
}
pub fn icon(&self) -> &'static str {
if self.is_dir { "📁" } else { "📄" }
}
}
-1
View File
@@ -1,4 +1,3 @@
use super::*;
use crate::rclone_install::RcloneApp;
use serde_json::Value;
use std::collections::HashMap;
+7 -4
View File
@@ -1,11 +1,14 @@
use std::fs;
use std::path::{Path, PathBuf};
use super::*;
use std::fs;
use std::path::PathBuf;
pub fn list_directory(path: &str) -> Result<Vec<FileInfo>, String> {
let p = if path.is_empty() {
if cfg!(windows) { PathBuf::from("C:\\") } else { PathBuf::from("/") }
if cfg!(windows) {
PathBuf::from("C:\\")
} else {
PathBuf::from("/")
}
} else {
PathBuf::from(path)
};
+21 -2
View File
@@ -4,6 +4,7 @@ use serde_json::Value;
/// Получить список всех удаленных хранилищ
pub fn list(app: &RcloneApp) -> Result<Vec<Remote>, String> {
log::debug!("Получение списка удаленных хранилищ");
let output = app.run_command(&["listremotes"])?;
let mut remotes = Vec::new();
@@ -14,6 +15,7 @@ pub fn list(app: &RcloneApp) -> Result<Vec<Remote>, String> {
if let Ok(config) = get_config(app, name) {
remotes.push(config);
} else {
log::warn!("Не удалось получить конфигурацию для remote '{}'", name);
// Если не удалось получить конфиг, добавляем базовую информацию
remotes.push(Remote {
name: name.to_string(),
@@ -24,11 +26,13 @@ pub fn list(app: &RcloneApp) -> Result<Vec<Remote>, String> {
}
}
log::info!("Найдено {} удаленных хранилищ", remotes.len());
Ok(remotes)
}
/// Получить конфигурацию конкретного remote
pub fn get_config(app: &RcloneApp, remote_name: &str) -> Result<Remote, String> {
log::debug!("Получение конфигурации для remote: {}", remote_name);
let output = app.run_command(&["config", "dump"])?;
let configs: Value = serde_json::from_str(&output)
@@ -54,13 +58,16 @@ pub fn get_config(app: &RcloneApp, remote_name: &str) -> Result<Remote, String>
}
}
log::debug!("Получена конфигурация для {} типа {}", remote_name, r#type);
Ok(Remote {
name: remote_name.to_string(),
r#type,
config: config_map,
})
} else {
Err(format!("Remote '{}' не найден", remote_name))
let error_msg = format!("Remote '{}' не найден", remote_name);
log::error!("{}", error_msg);
Err(error_msg)
}
}
@@ -71,6 +78,7 @@ pub fn create(
r#type: &str,
config: &HashMap<String, String>,
) -> Result<(), String> {
log::info!("Создание нового remote: {} типа {}", name, r#type);
let mut args = vec!["config", "create", name, r#type];
for (key, value) in config {
@@ -79,11 +87,13 @@ pub fn create(
}
app.run_command(&args)?;
log::info!("Remote {} успешно создан", name);
Ok(())
}
/// Обновить конфигурацию remote
pub fn update(app: &RcloneApp, name: &str, config: &HashMap<String, String>) -> Result<(), String> {
log::info!("Обновление конфигурации remote: {}", name);
let mut args = vec!["config", "update", name];
for (key, value) in config {
@@ -92,24 +102,33 @@ pub fn update(app: &RcloneApp, name: &str, config: &HashMap<String, String>) ->
}
app.run_command(&args)?;
log::info!("Конфигурация remote {} успешно обновлена", name);
Ok(())
}
/// Удалить remote
pub fn delete(app: &RcloneApp, name: &str) -> Result<(), String> {
log::info!("Удаление remote: {}", name);
app.run_command(&["config", "delete", name])?;
log::info!("Remote {} успешно удален", name);
Ok(())
}
/// Проверить доступность remote
pub fn check(app: &RcloneApp, remote_name: &str) -> Result<bool, String> {
log::debug!("Проверка доступности remote: {}", remote_name);
let result = app.run_command(&["lsd", remote_name, "--max-depth", "1"]);
match result {
Ok(_) => Ok(true),
Ok(_) => {
log::debug!("Remote {} доступен", remote_name);
Ok(true)
}
Err(e) => {
if e.contains("directory not found") {
log::warn!("Remote {} существует, но пуст", remote_name);
Ok(true) // Remote существует, но пустой
} else {
log::error!("Ошибка доступа к remote {}: {}", remote_name, e);
Err(e)
}
}
-1
View File
@@ -1,6 +1,5 @@
use super::*;
use crate::rclone_install::RcloneApp;
use serde_json::Value;
/// Скопировать файлы/директории
pub fn copy(