feat(all): Add loging
This commit is contained in:
1 parent
25080e3cca
commit
dfa7c463ac
10 files changed
+108
-45
No files matched your search
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user