fix: folder copy is harder than it looks
This commit is contained in:
parent
4760406224
commit
41f9b6f3f5
38
Cargo.lock
generated
38
Cargo.lock
generated
|
@ -292,6 +292,15 @@ version = "1.0.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0"
|
||||
|
||||
[[package]]
|
||||
name = "copy_dir"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "543d1dd138ef086e2ff05e3a48cf9da045da2033d16f8538fd76b86cd49b2ca3"
|
||||
dependencies = [
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation-sys"
|
||||
version = "0.8.7"
|
||||
|
@ -849,6 +858,15 @@ version = "1.0.18"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
|
||||
|
||||
[[package]]
|
||||
name = "same-file"
|
||||
version = "1.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
|
||||
dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "scopeguard"
|
||||
version = "1.2.0"
|
||||
|
@ -920,6 +938,7 @@ dependencies = [
|
|||
"chrono",
|
||||
"clap",
|
||||
"color-eyre",
|
||||
"copy_dir",
|
||||
"futures",
|
||||
"jsonrpsee",
|
||||
"serde",
|
||||
|
@ -1172,6 +1191,16 @@ version = "0.9.5"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
|
||||
[[package]]
|
||||
name = "walkdir"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b"
|
||||
dependencies = [
|
||||
"same-file",
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.0+wasi-snapshot-preview1"
|
||||
|
@ -1233,6 +1262,15 @@ version = "0.2.93"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-util"
|
||||
version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
|
||||
dependencies = [
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.52.0"
|
||||
|
|
|
@ -9,6 +9,7 @@ base64 = "0.22.1"
|
|||
chrono = "0.4.38"
|
||||
clap = { version = "4.5.17", features = ["derive"] }
|
||||
color-eyre = "0.6.3"
|
||||
copy_dir = "0.1.3"
|
||||
futures = "0.3.30"
|
||||
jsonrpsee = { version = "0.24.3", features = ["macros", "async-client"] }
|
||||
serde = { version = "1.0.209", features = ["derive"] }
|
||||
|
|
20
src/main.rs
20
src/main.rs
|
@ -1,21 +1,20 @@
|
|||
use std::fs::{create_dir_all, remove_file, rename, write, File, OpenOptions};
|
||||
use copy_dir::copy_dir;
|
||||
use std::fs::{create_dir_all, remove_file, write, File, OpenOptions};
|
||||
use std::io::{BufRead, BufReader, Write};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Stdio;
|
||||
use std::time::Duration;
|
||||
|
||||
use askama::Template;
|
||||
use base64::prelude::BASE64_STANDARD;
|
||||
use base64::Engine;
|
||||
use chrono::{DateTime, Local};
|
||||
use chrono::{DateTime, Days, Local};
|
||||
use clap::{command, Parser};
|
||||
use color_eyre::eyre::{eyre, Result};
|
||||
use color_eyre::eyre::{eyre, OptionExt, Result};
|
||||
use futures::future::join_all;
|
||||
use jsonrpsee::async_client::{Client, ClientBuilder};
|
||||
use serde_json::Value;
|
||||
use tempfile::tempdir;
|
||||
use tokio::process::Command;
|
||||
use tokio::task::yield_now;
|
||||
use tokio_util::codec::{FramedRead, LinesCodec};
|
||||
|
||||
use crate::jsonrpc::RpcClient;
|
||||
|
@ -69,7 +68,11 @@ async fn generate_post(config: &Config, client: &mut Client) -> Result<String> {
|
|||
}
|
||||
let mut template = PostTemplate {
|
||||
date: day.to_rfc3339(),
|
||||
date_title: day.format("%d.%m.%Y").to_string(),
|
||||
date_title: day
|
||||
.checked_sub_days(Days::new(1))
|
||||
.ok_or_eyre("Gestern gab es nicht?????????")?
|
||||
.format("%d.%m.%Y")
|
||||
.to_string(),
|
||||
..Default::default()
|
||||
};
|
||||
let mut msgs = Vec::new();
|
||||
|
@ -90,7 +93,7 @@ async fn generate_post(config: &Config, client: &mut Client) -> Result<String> {
|
|||
msgs.push(Message {
|
||||
content: get_msg_text(&v).unwrap_or("").to_string(),
|
||||
attachments,
|
||||
time: get_msg_time(&v).unwrap(),
|
||||
time: get_msg_time(&v).ok_or_eyre("Message without time???")?,
|
||||
});
|
||||
}
|
||||
if msgs.is_empty() {
|
||||
|
@ -98,7 +101,6 @@ async fn generate_post(config: &Config, client: &mut Client) -> Result<String> {
|
|||
};
|
||||
template.messages = msgs;
|
||||
|
||||
println!("{}", template.render()?);
|
||||
write(tempdir.path().join("index.md"), template.render()?)?;
|
||||
}
|
||||
let folder: PathBuf = [config.output_folder.clone(), day.to_rfc3339()]
|
||||
|
@ -107,7 +109,7 @@ async fn generate_post(config: &Config, client: &mut Client) -> Result<String> {
|
|||
if folder.exists() {
|
||||
return Err(eyre!("Blog folder already exists"));
|
||||
}
|
||||
rename(tempdir, folder)?;
|
||||
copy_dir(tempdir, folder)?;
|
||||
// Delete messages after we're finished with writing
|
||||
remove_file(file)?;
|
||||
Ok(day.to_rfc3339())
|
||||
|
|
Loading…
Reference in a new issue