Skip to content

Commit

Permalink
try WalkDir as glob seems broken on OpenBSD
Browse files Browse the repository at this point in the history
  • Loading branch information
rubyroobs committed Oct 11, 2024
1 parent ed3daac commit ab609df
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 39 deletions.
20 changes: 20 additions & 0 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 @@ -30,6 +30,7 @@ serde_json = "1.0.128"
tokio = { version = "1.34.0", features = ["full"] }
tokio-rustls = "0.26.0"
url = "2.5.0"
walkdir = "2.5.0"
webpki-roots = "0.26"
x509-parser = "0.16.0"

Expand Down
78 changes: 39 additions & 39 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use handlebars::Handlebars;
use log::{debug, error};
use serde::Serialize;
use serde_json::json;
use walkdir::WalkDir;

const MAX_FS_CACHE_ENTRIES: usize = 512;
const MAX_FS_CACHE_LONG_TTL_MS: u64 = 14_400_000;
Expand Down Expand Up @@ -78,50 +79,49 @@ impl ServerContext {
}

fn register_handlebars_templates(&self) {
let base_data_path = format!("{}/", self.config().partials_path());

for entry in
glob(&format!("{}**/*.hbs", base_data_path)).expect("Failed to read data glob pattern")
for entry in WalkDir::new(self.config().partials_path())
.follow_links(false)
.into_iter()
.filter_map(|e| e.ok())
{
match entry {
Ok(path_buf) => {
let partial_name = path_buf
.to_str()
.unwrap()
.strip_prefix(&base_data_path)
.unwrap()
.strip_suffix(".hbs")
.unwrap()
.to_string();

match self.fs_read(path_buf) {
Ok(data) => match std::str::from_utf8(&data) {
Ok(value) => {
let mut handlebars = self.handlebars.lock().unwrap();
match handlebars.register_template_string(&partial_name, value) {
Ok(_) => {}
Err(err) => error!(
"ERROR registering handlebar partial {}: {}",
partial_name, err
),
}
let f_name = entry.file_name().to_string_lossy();

if f_name.ends_with(".hbs") {
let path_buf = entry.into_path();

let partial_name = path_buf
.to_str()
.unwrap()
.strip_prefix(&format!("{}/", self.config().partials_path()))
.unwrap()
.strip_suffix(".hbs")
.unwrap()
.to_string();

match self.fs_read(path_buf) {
Ok(data) => match std::str::from_utf8(&data) {
Ok(value) => {
let mut handlebars = self.handlebars.lock().unwrap();
match handlebars.register_template_string(&partial_name, value) {
Ok(_) => {}
Err(err) => error!(
"ERROR registering handlebar partial {}: {}",
partial_name, err
),
}
Err(err) => error!(
"ERROR loading handlebar partial {} as UTF-8: {}",
partial_name, err
),
},
Err(err) => {
error!(
"ERROR loading handlebar partial file {}: {}",
partial_name, err
)
}
Err(err) => error!(
"ERROR loading handlebar partial {} as UTF-8: {}",
partial_name, err
),
},
Err(err) => {
error!(
"ERROR loading handlebar partial file {}: {}",
partial_name, err
)
}
}
Err(err) => {
error!("ERROR loading JSON files by glob: {:?}", err)
}
}
}

Expand Down

0 comments on commit ab609df

Please sign in to comment.