index : static-web-server.git

ascending towards madness

author Jose Quintana <joseluisquintana20@gmail.com> 2021-06-22 15:00:55.0 +00:00:00
committer Jose Quintana <joseluisquintana20@gmail.com> 2021-06-22 15:31:00.0 +00:00:00
commit
f9765867681f9cc6645a0d4b35fa118d011d5b73 [patch]
tree
5c4e05a1e4dbc4b1ef542308f23ef4f9862f445b
parent
d9a773a28dddf770def3e5a276b60bada6a5050b
download
f9765867681f9cc6645a0d4b35fa118d011d5b73.tar.gz

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(-)

diff --git a/Cargo.lock b/Cargo.lock
index 0e8c0d6..f94a9c9 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -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"
diff --git a/Cargo.toml b/Cargo.toml
index c252124..54f3a50 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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
diff --git a/src/bin/server.rs b/src/bin/server.rs
index 5a3579c..f43a938 100644
--- a/src/bin/server.rs
+++ b/src/bin/server.rs
@@ -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 {
diff --git a/src/staticfile_middleware/staticfile.rs b/src/staticfile_middleware/staticfile.rs
index b211118..083f925 100644
--- a/src/staticfile_middleware/staticfile.rs
+++ b/src/staticfile_middleware/staticfile.rs
@@ -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 {