Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ serde = { version = "1.0.219", features = ["derive"] }
serde_yaml_ng = "0.10.0"
tokio-stream = { version = "0.1.17", features = ["fs"] }
time = { version = "0.3.41", features = ["formatting"] }
chrono = "0.4.42"

# [patch."https://github.com/silicon-heaven/libshvclient-rs"]
# shvclient = { path = "../libshvclient-rs" }
Expand Down
2 changes: 1 addition & 1 deletion src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ async fn sync_site_legacy(
fn msec_to_log2_filename(msec: i64) -> String {
shvproto::DateTime::from_epoch_msec(msec)
.to_chrono_datetime()
.format("%Y-%m-%dT%H:%M:%S.log2")
.format("%Y-%m-%dT%H-%M-%S-%3f.log2")
.to_string()
}

Expand Down
18 changes: 13 additions & 5 deletions src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::pin::Pin;
use std::sync::Arc;

use async_compression::tokio::write::GzipEncoder;
use chrono::TimeZone;
use futures::io::{BufReader, BufWriter};
use futures::{Stream, StreamExt, TryStreamExt};
use log::{error, info, warn};
Expand Down Expand Up @@ -798,6 +799,17 @@ async fn pushlog_handler(
).into())
}

fn file_name_to_file_msec(filename: &str) -> Result<i64, String> {
let without_ext = filename
.strip_suffix(".log2")
.ok_or_else(|| format!("Invalid file extension in '{filename}'"))?;

let datetime = chrono::NaiveDateTime::parse_from_str(without_ext, "%Y-%m-%dT%H-%M-%S-%3f")
.map_err(|e| format!("Failed to parse '{filename}': {e}"))?;

Ok(chrono::Utc.from_utc_datetime(&datetime).timestamp_millis())
}

pub async fn getlog_handler(
site_path: &str,
params: &GetLog2Params,
Expand Down Expand Up @@ -844,17 +856,13 @@ pub async fn getlog_handler(
match &params.since {
GetLog2Since::DateTime(date_time) => {
let since_ms = date_time.epoch_msec();
let file_name_to_msec = |file_name: &str| file_name
.strip_suffix(".log2")
.and_then(|file| shvproto::DateTime::from_iso_str(file).ok().as_ref().map(shvproto::DateTime::epoch_msec))
.unwrap_or(i64::MAX);

log_files
.iter()
.map(DirEntry::file_name)
.enumerate()
.rev()
.find(|(_,file)| file_name_to_msec(&file.to_string_lossy()) < since_ms)
.find(|(_,file)| file_name_to_file_msec(&file.to_string_lossy()).is_ok_and(|ms| ms < since_ms))
.map(|(idx, _)| idx)
.unwrap_or(0)
}
Expand Down