Use 'normpath' to fix canonicalization on Windows.

This commit is contained in:
Sergio Benitez 2021-02-22 18:12:30 -08:00
parent 374ad8804c
commit 73037c6620
2 changed files with 5 additions and 3 deletions

View File

@ -13,7 +13,7 @@ edition = "2018"
[features]
# Internal use only.
templates = ["serde", "serde_json", "glob", "notify"]
templates = ["serde", "serde_json", "glob", "notify", "normpath"]
databases = [
"serde", "r2d2", "tokio/rt", "tokio/rt-multi-thread",
"rocket_contrib_codegen/database_attribute"
@ -57,6 +57,7 @@ handlebars = { version = "3.0", optional = true }
glob = { version = "0.3", optional = true }
tera = { version = "1.0.2", optional = true }
notify = { version = "4.0.6", optional = true }
normpath = { version = "0.2", optional = true }
# UUID dependencies.
uuid = { version = ">=0.7.0, <0.9.0", optional = true }

View File

@ -4,6 +4,7 @@ use std::collections::HashMap;
use crate::templates::{Engines, TemplateInfo};
use rocket::http::ContentType;
use normpath::PathExt;
pub(crate) struct Context {
/// The root of the template directory.
@ -19,8 +20,8 @@ impl Context {
/// template engine, and store all of the initialized state in a `Context`
/// structure, which is returned if all goes well.
pub fn initialize(root: &Path) -> Option<Context> {
let root = match root.canonicalize() {
Ok(root) => root,
let root = match root.normalize() {
Ok(root) => root.into_path_buf(),
Err(e) => {
error!("Invalid template directory '{}': {}.", root.display(), e);
return None;