fix: base path of static file not resolved properly
it canonicalizes the base path (absolute path) during staticfile base
path resolving since in macos for example, during testing using temp
dirs causes issues because the temp directory base path generated was
not obviously the same as a given base path before being
resolved (canonicalized)
it resolves devel ci build 24 for macos
https://github.com/joseluisq/static-web-server/actions/runs/959808294
Diff
Cargo.lock | 12 +-----------
Cargo.toml | 2 +-
src/bin/server.rs | 6 +++---
src/staticfile_middleware/staticfile.rs | 8 +++++---
4 files changed, 10 insertions(+), 18 deletions(-)
@@ -889,7 +889,7 @@ dependencies = [
"percent-encoding 2.1.0",
"signal",
"structopt",
"tempdir",
"tempfile",
"time",
"url",
]
@@ -930,16 +930,6 @@ dependencies = [
]
[[package]]
name = "tempdir"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8"
dependencies = [
"rand 0.4.6",
"remove_dir_all",
]
[[package]]
name = "tempfile"
version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -51,7 +51,7 @@ version = "0.3"
openssl = { version = "0.10", features = ["vendored"] }
hyper = "0.10"
iron-test = "0.6"
tempdir = "0.3"
tempfile = "3"
[profile.release]
opt-level = 3
@@ -15,7 +15,7 @@ fn main() {
mod test {
extern crate hyper;
extern crate iron_test;
extern crate tempdir;
extern crate tempfile;
use super::*;
use static_web_server::config::Options;
@@ -27,7 +27,7 @@ mod test {
use self::hyper::header::Headers;
use self::iron_test::{request, response};
use self::tempdir::TempDir;
use self::tempfile::TempDir;
use iron::headers::{ContentLength, ContentType};
use iron::status;
@@ -35,7 +35,7 @@ mod test {
impl TestFilesystemSetup {
fn new() -> Self {
TestFilesystemSetup(TempDir::new("test").expect("Could not create test directory"))
TestFilesystemSetup(TempDir::new().expect("Could not create test directory"))
}
fn path(&self) -> &Path {
@@ -63,6 +63,8 @@ impl Staticfile {
};
let base_path = if is_assets { &self.assets } else { &self.root };
let base_path = PathBuf::from(helpers::adjust_canonicalization(base_path.canonicalize()?));
let path_resolved = PathBuf::from(helpers::adjust_canonicalization(
path_resolved.canonicalize()?,
));
@@ -318,7 +320,7 @@ fn parse_last_modified(modified: SystemTime) -> Result<time::Tm, Box<dyn error::
mod test {
extern crate hyper;
extern crate iron_test;
extern crate tempdir;
extern crate tempfile;
use super::*;
@@ -327,14 +329,14 @@ mod test {
use self::hyper::header::Headers;
use self::iron_test::request;
use self::tempdir::TempDir;
use self::tempfile::TempDir;
use iron::status;
struct TestFilesystemSetup(TempDir);
impl TestFilesystemSetup {
fn new() -> Self {
TestFilesystemSetup(TempDir::new("test").expect("Could not create test directory"))
TestFilesystemSetup(TempDir::new().expect("Could not create test directory"))
}
fn path(&self) -> &Path {