rm shellexpand
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run

This commit is contained in:
2025-06-09 01:32:09 +09:00
parent a17d2c9d66
commit a936d9c0ce
2 changed files with 24 additions and 92 deletions

View File

@ -1,17 +1,9 @@
[package] [package]
name = "aibot" name = "ai"
authors = ["syui"] authors = ["syui"]
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
description = "ai.bot - Bluesky AT Protocol Bot" description = "latest@2024-08-18"
[[bin]]
name = "aibot"
path = "src/main.rs"
[[bin]]
name = "ai"
path = "src/alias.rs"
[dependencies] [dependencies]
seahorse = "*" seahorse = "*"
@ -27,7 +19,3 @@ rustc-serialize = "*"
toml = "*" toml = "*"
iso8601-timestamp = "*" iso8601-timestamp = "*"
sysinfo = "*" sysinfo = "*"
[dev-dependencies]
mockito = "1.2"
tokio-test = "0.4"

View File

@ -8,91 +8,35 @@ use std::io::Write;
use std::path::Path; use std::path::Path;
pub fn data_file(s: &str) -> String { pub fn data_file(s: &str) -> String {
// 新しい設定ディレクトリ(優先) let file = "/.config/ai/";
let new_config_dir = "/.config/syui/ai/bot/"; let mut f = shellexpand::tilde("~").to_string();
let mut new_path = shellexpand::tilde("~").to_string(); f.push_str(&file);
new_path.push_str(&new_config_dir); let path = Path::new(&f);
if path.is_dir() == false {
// 旧設定ディレクトリ(互換性のため) let _ = fs::create_dir_all(f.clone());
let old_config_dir = "/.config/ai/";
let mut old_path = shellexpand::tilde("~").to_string();
old_path.push_str(&old_config_dir);
// 新しいディレクトリを作成
let new_dir = Path::new(&new_path);
if !new_dir.is_dir() {
let _ = fs::create_dir_all(new_path.clone());
} }
match &*s {
let filename = match &*s { "toml" => f + &"token.toml",
"toml" => "token.toml", "json" => f + &"token.json",
"json" => "token.json", "refresh" => f + &"refresh.toml",
"refresh" => "refresh.toml", _ => f + &"." + &s,
_ => &format!(".{}", s),
};
let new_file = new_path.clone() + filename;
let old_file = old_path + filename;
// 新しいパスにファイルが存在する場合は新しいパスを使用
if Path::new(&new_file).exists() {
return new_file;
} }
// 旧パスにファイルが存在し、新しいパスに存在しない場合は移行を試行
if Path::new(&old_file).exists() && !Path::new(&new_file).exists() {
if let Ok(_) = fs::copy(&old_file, &new_file) {
eprintln!("Migrated config file: {} -> {}", old_file, new_file);
return new_file;
}
}
// デフォルトは新しいパス
new_file
} }
pub fn log_file(s: &str) -> String { pub fn log_file(s: &str) -> String {
// 新しい設定ディレクトリ(優先) let file = "/.config/ai/txt/";
let new_log_dir = "/.config/syui/ai/bot/txt/"; let mut f = shellexpand::tilde("~").to_string();
let mut new_path = shellexpand::tilde("~").to_string(); f.push_str(&file);
new_path.push_str(&new_log_dir); let path = Path::new(&f);
if path.is_dir() == false {
// 旧設定ディレクトリ(互換性のため) let _ = fs::create_dir_all(f.clone());
let old_log_dir = "/.config/ai/txt/";
let mut old_path = shellexpand::tilde("~").to_string();
old_path.push_str(&old_log_dir);
// 新しいディレクトリを作成
let new_dir = Path::new(&new_path);
if !new_dir.is_dir() {
let _ = fs::create_dir_all(new_path.clone());
} }
match &*s {
let filename = match &*s { "n1" => f + &"notify_cid.txt",
"n1" => "notify_cid.txt", "n2" => f + &"notify_cid_run.txt",
"n2" => "notify_cid_run.txt", "c1" => f + &"comment_cid.txt",
"c1" => "comment_cid.txt", _ => f + &s,
_ => s,
};
let new_file = new_path.clone() + filename;
let old_file = old_path + filename;
// 新しいパスにファイルが存在する場合は新しいパスを使用
if Path::new(&new_file).exists() {
return new_file;
} }
// 旧パスにファイルが存在し、新しいパスに存在しない場合は移行を試行
if Path::new(&old_file).exists() && !Path::new(&new_file).exists() {
if let Ok(_) = fs::copy(&old_file, &new_file) {
eprintln!("Migrated log file: {} -> {}", old_file, new_file);
return new_file;
}
}
// デフォルトは新しいパス
new_file
} }
impl Token { impl Token {