From 068efecd28ac6e35cf8fce261642baa7911efc0c Mon Sep 17 00:00:00 2001 From: realaravinth Date: Mon, 5 Jul 2021 11:34:46 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20=20@=20081ec?= =?UTF-8?q?4c286bf3eaf6ed37df03cd838da58c567de=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cache_buster/processor/index.html | 2 +- search-index.js | 2 +- src/cache_buster/processor.rs.html | 292 +++++++++++------------------ 3 files changed, 115 insertions(+), 181 deletions(-) diff --git a/cache_buster/processor/index.html b/cache_buster/processor/index.html index 07279fe..ec43726 100644 --- a/cache_buster/processor/index.html +++ b/cache_buster/processor/index.html @@ -1,7 +1,7 @@ cache_buster::processor - Rust

Module cache_buster::processor[][src]

Module describing file processor that changes filenames to setup cache-busting

+ Change settings

Module cache_buster::processor[][src]

Module describing file processor that changes filenames to setup cache-busting

Run the following during build using build.rs:

diff --git a/search-index.js b/search-index.js
index 696d1d2..7b31d32 100644
--- a/search-index.js
+++ b/search-index.js
@@ -1,5 +1,5 @@
 var searchIndex = JSON.parse('{\
 "actix_web":{"doc":"","t":[3,17,3,3,3,12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,3,11,11,11,11,11,11,11,11,11,11,11,5,5,0,11,11,11,11,11,11,11,11,11,11,11,11,11,5,11,11,11,3,5,3,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,5],"n":["Asset","CACHE_AGE","FILES","Favicons","INDEX","__private_field","__private_field","borrow","borrow","borrow","borrow","borrow","borrow","borrow","borrow_mut","borrow_mut","borrow_mut","borrow_mut","borrow_mut","borrow_mut","borrow_mut","deref","deref","favicons","from","from","from","from","from","from","from","get","get","get","get","handle_assets","handle_favicons","index","initialize","initialize","into","into","into","into","into","into","into","iter","iter","iter","iter","main","register","register","register","serve_index","services","static_files","try_from","try_from","try_from","try_from","try_from","try_from","try_from","try_into","try_into","try_into","try_into","try_into","try_into","try_into","type_id","type_id","type_id","type_id","type_id","type_id","type_id","vzip","vzip","vzip","vzip","vzip","vzip","vzip","get_index"],"q":["actix_web","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","actix_web::index"],"d":["Embed files. Or not. You can also read files dynamically","Set a riddicolusly high cache age","create filemap","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""],"i":[0,0,0,0,0,1,2,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,0,1,2,3,4,5,6,7,3,3,6,6,0,0,0,1,2,1,2,3,4,5,6,7,3,3,6,6,0,4,5,7,0,0,0,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,0],"f":[null,null,null,null,null,null,null,[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[],["files",3]],[[],["string",3]],null,[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[["str",15]],[["option",4],["cow",4]]],[[["str",15]],[["option",4],["cow",4]]],[[["str",15]],[["option",4],["cow",4]]],[[["str",15]],[["option",4],["cow",4]]],[[["str",15]],["httpresponse",3]],[[["str",15]],["httpresponse",3]],null,[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[],["filenames",4]],[[],["filenames",4]],[[]],[[],["result",6]],[[["appservice",3]]],[[["appservice",3]]],[[["appservice",3]]],null,[[["serviceconfig",3]]],null,[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["typeid",3]],[[],["typeid",3]],[[],["typeid",3]],[[],["typeid",3]],[[],["typeid",3]],[[],["typeid",3]],[[],["typeid",3]],[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[],["string",3]]],"p":[[3,"FILES"],[3,"INDEX"],[3,"Asset"],[3,"static_files"],[3,"serve_index"],[3,"Favicons"],[3,"favicons"]]},\
-"cache_buster":{"doc":"What is cache busting?","t":[17,0,0,3,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,3,3,4,13,13,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11],"n":["CACHE_BUSTER_DATA_FILE","filemap","processor","Files","borrow","borrow_mut","clone","clone_into","deserialize","eq","fmt","from","get","get_full_path","into","ne","new","serialize","to_owned","try_from","try_into","type_id","Buster","BusterBuilder","BusterBuilderError","UninitializedField","ValidationError","borrow","borrow","borrow","borrow_mut","borrow_mut","borrow_mut","build","clone","clone","clone_into","clone_into","copy","default","fmt","fmt","fmt","follow_links","from","from","from","from","from","into","into","into","mime_types","no_hash","prefix","process","result","source","to_owned","to_owned","to_string","try_from","try_from","try_from","try_into","try_into","try_into","type_id","type_id","type_id"],"q":["cache_buster","","","cache_buster::filemap","","","","","","","","","","","","","","","","","","","cache_buster::processor","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""],"d":["file to which filemap is written during compilation …","Module describing runtime compoenet for fetching modified …","Module describing file processor that changes filenames …","Filemap struct","","","","","","","","","Get relative file path","Get file path","","","Load filemap in main program. Should be called from main …","","","","","","Configuration for setting up cache-busting","Builder for Buster.","Error type for BusterBuilder","Uninitialized field","Custom validation error","","","","","","","Builds a new Buster.","","","","","copy other non-hashed files from source dire to result …","","","","","follow symlinks?","","","","","","","","","mime_types for hashing","exclude these files for hashing. They will be copied over …","route prefixes","Processes files.","directory for writing results","source directory","","","","","","","","","","","",""],"i":[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,2,2,3,2,4,3,2,4,3,3,4,3,4,3,3,2,2,4,3,3,2,2,2,4,3,2,4,3,3,3,4,3,3,3,4,2,3,2,4,3,2,4,3,2,4],"f":[null,null,null,null,[[]],[[]],[[],["files",3]],[[]],[[],["result",4]],[[["files",3]],["bool",15]],[[["formatter",3]],["result",6]],[[]],[[["str",15]],[["option",4],["str",15]]],[[["str",15]],[["option",4],["string",3]]],[[]],[[["files",3]],["bool",15]],[[["str",15]]],[[],["result",4]],[[]],[[],["result",4]],[[],["result",4]],[[],["typeid",3]],null,null,null,null,null,[[]],[[]],[[]],[[]],[[]],[[]],[[],[["result",4],["buster",3],["busterbuildererror",4]]],[[],["busterbuilder",3]],[[],["buster",3]],[[]],[[]],[[["bool",15]]],[[]],[[["formatter",3]],["result",6]],[[["formatter",3]],["result",6]],[[["formatter",3]],["result",6]],[[["bool",15]]],[[]],[[["uninitializedfielderror",3]]],[[]],[[["string",3]]],[[]],[[]],[[]],[[]],[[["into",8],["vec",3]]],[[["vec",3],["str",15]]],[[["into",8],["string",3]]],[[],[["result",4],["error",3]]],[[["into",8],["string",3]]],[[["into",8],["string",3]]],[[]],[[]],[[],["string",3]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["typeid",3]],[[],["typeid",3]],[[],["typeid",3]]],"p":[[3,"Files"],[4,"BusterBuilderError"],[3,"BusterBuilder"],[3,"Buster"]]}\
+"cache_buster":{"doc":"What is cache busting?","t":[17,0,0,3,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,3,3,4,13,13,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11],"n":["CACHE_BUSTER_DATA_FILE","filemap","processor","Files","borrow","borrow_mut","clone","clone_into","deserialize","eq","fmt","from","get","get_full_path","into","ne","new","serialize","to_owned","try_from","try_into","type_id","Buster","BusterBuilder","BusterBuilderError","UninitializedField","ValidationError","borrow","borrow","borrow","borrow_mut","borrow_mut","borrow_mut","build","clone","clone","clone_into","clone_into","copy","default","fmt","fmt","fmt","follow_links","from","from","from","from","from","into","into","into","mime_types","no_hash","prefix","process","result","source","to_owned","to_owned","to_string","try_from","try_from","try_from","try_into","try_into","try_into","type_id","type_id","type_id"],"q":["cache_buster","","","cache_buster::filemap","","","","","","","","","","","","","","","","","","","cache_buster::processor","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""],"d":["file to which filemap is written during compilation …","Module describing runtime compoenet for fetching modified …","Module describing file processor that changes filenames …","Filemap struct","","","","","","","","","Get relative file path","Get file path","","","Load filemap in main program. Should be called from main …","","","","","","Configuration for setting up cache-busting","Builder for Buster.","Error type for BusterBuilder","Uninitialized field","Custom validation error","","","","","","","Builds a new Buster.","","","","","copy other non-hashed files from source dire to result …","","","","","follow symlinks?","","","","","","","","","mime_types for hashing","exclude these files for hashing. They will be copied over …","route prefixes","Processes files.","directory for writing results","source directory","","","","","","","","","","","",""],"i":[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,2,2,3,2,4,3,2,4,3,3,4,3,4,3,3,2,2,4,3,3,2,2,2,4,3,2,4,3,3,3,4,3,3,3,4,2,3,2,4,3,2,4,3,2,4],"f":[null,null,null,null,[[]],[[]],[[],["files",3]],[[]],[[],["result",4]],[[["files",3]],["bool",15]],[[["formatter",3]],["result",6]],[[]],[[["str",15]],[["option",4],["str",15]]],[[["str",15]],[["option",4],["string",3]]],[[]],[[["files",3]],["bool",15]],[[["str",15]]],[[],["result",4]],[[]],[[],["result",4]],[[],["result",4]],[[],["typeid",3]],null,null,null,null,null,[[]],[[]],[[]],[[]],[[]],[[]],[[],[["busterbuildererror",4],["result",4],["buster",3]]],[[],["busterbuilder",3]],[[],["buster",3]],[[]],[[]],[[["bool",15]]],[[]],[[["formatter",3]],["result",6]],[[["formatter",3]],["result",6]],[[["formatter",3]],["result",6]],[[["bool",15]]],[[]],[[["uninitializedfielderror",3]]],[[]],[[["string",3]]],[[]],[[]],[[]],[[]],[[["into",8],["vec",3]]],[[["vec",3],["str",15]]],[[["into",8],["string",3]]],[[],[["result",4],["error",3]]],[[["into",8],["string",3]]],[[["into",8],["string",3]]],[[]],[[]],[[],["string",3]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["typeid",3]],[[],["typeid",3]],[[],["typeid",3]]],"p":[[3,"Files"],[4,"BusterBuilderError"],[3,"BusterBuilder"],[3,"Buster"]]}\
 }');
 if (window.initSearch) {window.initSearch(searchIndex)};
\ No newline at end of file
diff --git a/src/cache_buster/processor.rs.html b/src/cache_buster/processor.rs.html
index a5318f7..ce0751f 100644
--- a/src/cache_buster/processor.rs.html
+++ b/src/cache_buster/processor.rs.html
@@ -419,39 +419,6 @@
 416
 417
 418
-419
-420
-421
-422
-423
-424
-425
-426
-427
-428
-429
-430
-431
-432
-433
-434
-435
-436
-437
-438
-439
-440
-441
-442
-443
-444
-445
-446
-447
-448
-449
-450
-451
 
 /*
 * Copyright (C) 2021  Aravinth Manivannan <realaravinth@batsense.net>
@@ -576,6 +543,34 @@
         self.init()?;
         let mut file_map: Files = Files::new(&self.result);
 
+        let mut process_worker = |path: &Path| {
+            let contents = Self::read_to_string(&path).unwrap();
+            let hash = Self::hasher(&contents);
+            let new_name = if self.no_hash.iter().any(|no_hash| {
+                let no_hash = Path::new(&self.source).join(&no_hash);
+                no_hash == path
+            }) {
+                format!(
+                    "{}.{}",
+                    path.file_stem().unwrap().to_str().unwrap(),
+                    path.extension().unwrap().to_str().unwrap()
+                )
+            } else {
+                format!(
+                    "{}.{}.{}",
+                    path.file_stem().unwrap().to_str().unwrap(),
+                    hash,
+                    path.extension().unwrap().to_str().unwrap()
+                )
+            };
+            self.copy(path, &new_name);
+            let (source, destination) = self.gen_map(path, &&new_name);
+            let _ = file_map.add(
+                source.to_str().unwrap().into(),
+                destination.to_str().unwrap().into(),
+            );
+        };
+
         for entry in WalkDir::new(&self.source)
             .follow_links(self.follow_links)
             .into_iter()
@@ -586,34 +581,6 @@
             if !path.is_dir() {
                 let path = Path::new(&path);
 
-                let mut process_worker = |path: &Path| {
-                    let contents = Self::read_to_string(&path).unwrap();
-                    let hash = Self::hasher(&contents);
-                    let new_name = if self.no_hash.iter().any(|no_hash| {
-                        let no_hash = Path::new(&self.source).join(&no_hash);
-                        no_hash == path
-                    }) {
-                        format!(
-                            "{}.{}",
-                            path.file_stem().unwrap().to_str().unwrap(),
-                            path.extension().unwrap().to_str().unwrap()
-                        )
-                    } else {
-                        format!(
-                            "{}.{}.{}",
-                            path.file_stem().unwrap().to_str().unwrap(),
-                            hash,
-                            path.extension().unwrap().to_str().unwrap()
-                        )
-                    };
-                    self.copy(path, &new_name);
-                    let (source, destination) = self.gen_map(path, &&new_name);
-                    let _ = file_map.add(
-                        source.to_str().unwrap().into(),
-                        destination.to_str().unwrap().into(),
-                    );
-                };
-
                 match self.mime_types.as_ref() {
                     Some(mime_types) => {
                         for mime_type in mime_types.iter() {
@@ -730,25 +697,11 @@
     /// data to the main program. This funtction sets that variable
     fn to_env(&self) {
         let json = serde_json::to_string(&self).unwrap();
-        //        println!("cargo:rustc-env={}={}", ENV_VAR_NAME, json);
         let res = Path::new(CACHE_BUSTER_DATA_FILE);
         if res.exists() {
             fs::remove_file(&res).unwrap();
         }
-
-        //       const PREFIX: &str = r##"pub const FILE_MAP: &str = r#" "##;
-        //       const POSTFIX: &str = r##""#;"##;
-
-        //       let content = format!("#[allow(dead_code)]\n{}{}{}", &PREFIX, &json, &POSTFIX);
-
-        //        fs::write(CACHE_BUSTER_DATA_FILE, content).unwrap();
         fs::write(CACHE_BUSTER_DATA_FILE, &json).unwrap();
-
-        // needed for testing load()
-        // if the above statement fails(println), then something's broken
-        // with the rust compiler. So not really worried about that.
-        //        #[cfg(test)]
-        //        std::env::set_var(ENV_VAR_NAME, serde_json::to_string(&self).unwrap());
     }
 
     #[cfg(test)]
@@ -764,37 +717,6 @@
 pub mod tests {
     use super::*;
 
-    fn hasher_works() {
-        delete_file();
-        let types = vec![
-            mime::IMAGE_PNG,
-            mime::IMAGE_SVG,
-            mime::IMAGE_JPEG,
-            mime::IMAGE_GIF,
-        ];
-
-        let config = BusterBuilder::default()
-            .source("./dist")
-            .result("./prod56")
-            .mime_types(types)
-            .copy(true)
-            .follow_links(true)
-            .build()
-            .unwrap();
-
-        config.process().unwrap();
-        let mut files = Files::load();
-
-        for (k, v) in files.map.drain() {
-            let src = Path::new(&k);
-            let dest = Path::new(&v);
-
-            assert_eq!(src.exists(), dest.exists());
-        }
-
-        cleanup(&config);
-    }
-
     pub fn cleanup(config: &Buster) {
         let _ = fs::remove_dir_all(&config.result);
         delete_file();
@@ -804,56 +726,6 @@
         let _ = fs::remove_file(&CACHE_BUSTER_DATA_FILE);
     }
 
-    fn prefix_works() {
-        delete_file();
-        let types = vec![
-            mime::IMAGE_PNG,
-            mime::IMAGE_SVG,
-            mime::IMAGE_JPEG,
-            mime::IMAGE_GIF,
-        ];
-
-        let no_hash = vec!["bell.svg", "eye.svg", "a/b/c/d/s/d/svg/10.svg"];
-
-        let config = BusterBuilder::default()
-            .source("./dist")
-            .result("/tmp/prod2i2")
-            .mime_types(types)
-            .copy(true)
-            .follow_links(true)
-            .prefix("/test")
-            .no_hash(no_hash.clone())
-            .build()
-            .unwrap();
-
-        config.process().unwrap();
-        let mut files = Files::load();
-
-        if let Some(prefix) = &config.prefix {
-            no_hash.iter().for_each(|file| {
-                assert!(files.map.iter().any(|(k, v)| {
-                    let source = Path::new(k);
-                    let dest = Path::new(&v[prefix.len()..]);
-                    let no_hash = Path::new(file);
-                    let stat = source == &Path::new(&config.source).join(file)
-                        && dest.exists()
-                        && no_hash.file_name() == dest.file_name();
-                    println!("[{}] file: {}", stat, file);
-                    stat
-                }));
-            });
-
-            for (k, v) in files.map.drain() {
-                let src = Path::new(&k);
-                let dest = Path::new(&v[prefix.len()..]);
-
-                assert_eq!(src.exists(), dest.exists());
-            }
-        }
-
-        cleanup(&config);
-    }
-
     #[test]
     fn no_hash_validation_works() {
         let types = vec![
@@ -876,32 +748,94 @@
             .is_err())
     }
 
-    //    #[test]
-    //    fn no_specific_mime() {
-    //        let no_hash = vec!["858fd6c482cc75111d54.module.wasm"];
-    //        let config = BusterBuilder::default()
-    //            .source("./dist")
-    //            .result("/tmp/prod2ii")
-    //            .copy(true)
-    //            .follow_links(true)
-    //            .no_hash(no_hash.clone())
-    //            .prefix("/test")
-    //            .build()
-    //            .unwrap();
-    //        config.process().unwrap();
-    //        let files = Files::load();
-    //        files.map.iter().any(|(k, v)| {
-    //            let dest = Path::new(&v[prefix.len()..]);
-    //            let no_hash = Path::new(file);
-    //            k == file && dest.exists() && no_hash.file_name() == dest.file_name()
-    //        });
-    //
-    //        cleanup(&config);
-    //    }
+    fn no_specific_mime() {
+        delete_file();
+        use std::{thread, time};
+
+        let sleep = time::Duration::from_secs(4);
+
+        thread::sleep(sleep);
+
+        const WASM: &str = "858fd6c482cc75111d54.module.wasm";
+        let no_hash = vec![WASM, "bell.svg", "eye.svg", "a/b/c/d/s/d/svg/10.svg"];
+        let config = BusterBuilder::default()
+            .source("./dist")
+            .result("/tmp/prod2ii")
+            .copy(true)
+            .follow_links(true)
+            .no_hash(no_hash.clone())
+            .build()
+            .unwrap();
+        config.process().unwrap();
+        let files = Files::load();
+
+        let no_hash_file = Path::new(&config.result).join(WASM);
+        assert!(files.map.iter().any(|(k, v)| {
+            let source = Path::new(&config.source).join(k);
+            let dest = Path::new(&v);
+            dest.file_name() == no_hash_file.file_name()
+                && dest.exists()
+                && source.file_name() == dest.file_name()
+        }));
+
+        no_hash.iter().for_each(|file| {
+            assert!(files.map.iter().any(|(k, v)| {
+                let source = Path::new(k);
+                let dest = Path::new(&v);
+                let no_hash = Path::new(file);
+                source == &Path::new(&config.source).join(file)
+                    && dest.exists()
+                    && no_hash.file_name() == dest.file_name()
+            }));
+        });
+
+        for (k, v) in files.map.iter() {
+            let src = Path::new(&k);
+            let dest = Path::new(&v);
+
+            assert_eq!(src.exists(), dest.exists());
+        }
+
+        cleanup(&config);
+    }
+
+    fn prefix_works() {
+        delete_file();
+        let types = vec![
+            mime::IMAGE_PNG,
+            mime::IMAGE_SVG,
+            mime::IMAGE_JPEG,
+            mime::IMAGE_GIF,
+        ];
+
+        let config = BusterBuilder::default()
+            .source("./dist")
+            .result("/tmp/prod2i")
+            .mime_types(types)
+            .copy(true)
+            .follow_links(true)
+            .prefix("/test")
+            .build()
+            .unwrap();
+
+        config.process().unwrap();
+        let mut files = Files::load();
+
+        if let Some(prefix) = &config.prefix {
+            for (k, v) in files.map.drain() {
+                let src = Path::new(&k);
+                let dest = Path::new(&v[prefix.len()..]);
+
+                assert_eq!(src.exists(), dest.exists());
+            }
+        }
+
+        cleanup(&config);
+    }
 
     pub fn runner() {
         prefix_works();
-        hasher_works();
+        no_specific_mime();
     }
 }