rm copy and address clippy lints
This commit is contained in:
parent
d2ba1e1af3
commit
7011c8c05c
5 changed files with 35 additions and 59 deletions
48
CHANGELOG.md
48
CHANGELOG.md
|
@ -2,50 +2,54 @@
|
||||||
|
|
||||||
### Added:
|
### Added:
|
||||||
|
|
||||||
- `Buster.no_hash` Option to exclude select files from processing. These
|
- `Buster.no_hash` Option to exclude select files from processing. These
|
||||||
files will be copied over without any processing for cache
|
files will be copied over without any processing for cache
|
||||||
busting(i.e, no renaming)
|
busting(i.e, no renaming)
|
||||||
|
|
||||||
- `Buster.source` is tracked by cargo
|
- `Buster.source` is tracked by cargo
|
||||||
|
|
||||||
|
## Removed:
|
||||||
|
|
||||||
|
- `copy` in `Processor`: current implementation copies all files by
|
||||||
|
default. That field was redundant.
|
||||||
|
|
||||||
### Changed:
|
### Changed:
|
||||||
|
|
||||||
- `Files::new()` takes a `&str`: Earlier versions were using
|
- `Files::new()` takes a `&str`: Earlier versions were using
|
||||||
environment variables to pass filemap information from `build.rs`
|
environment variables to pass filemap information from `build.rs`
|
||||||
component to program code but this proved to be unreliable. Starting
|
component to program code but this proved to be unreliable. Starting
|
||||||
with `0.2.0`, `cache_buster` will write filemap to
|
with `0.2.0`, `cache_buster` will write filemap to
|
||||||
`CACHE_BUSTER_DATA_FILE`(`./src/cache_buster_data.json`) and the user
|
`CACHE_BUSTER_DATA_FILE`(`./src/cache_buster_data.json`) and the user
|
||||||
is requested to read and pass the value to `File::new()`
|
is requested to read and pass the value to `File::new()`
|
||||||
|
|
||||||
- `Files.mime_types` now accepts an `Option<Vec<mime::Mime>>`. When it
|
- `Files.mime_types` now accepts an `Option<Vec<mime::Mime>>`. When it
|
||||||
is unset(i.e `None`), no mime based filtering is done and all files
|
is unset(i.e `None`), no mime based filtering is done and all files
|
||||||
inside source directory is considered for processing.
|
inside source directory is considered for processing.
|
||||||
|
|
||||||
- `Files::get_full_path()` and `Files::get()` now accept `impl
|
- `Files::get_full_path()` and `Files::get()` now accept `impl AsRef<str>` for path argument.
|
||||||
AsRef<str>` for path argument.
|
|
||||||
|
|
||||||
### Fixed:
|
### Fixed:
|
||||||
|
|
||||||
- `Files::get()` now behaves as it is described in the documentation
|
- `Files::get()` now behaves as it is described in the documentation
|
||||||
|
|
||||||
## 0.1.1
|
## 0.1.1
|
||||||
|
|
||||||
### Added:
|
### Added:
|
||||||
|
|
||||||
- Optional route prefix to `Processor`
|
- Optional route prefix to `Processor`
|
||||||
|
|
||||||
### Changed:
|
### Changed:
|
||||||
|
|
||||||
- `Files::load()` became `Files::new()`
|
- `Files::load()` became `Files::new()`
|
||||||
|
|
||||||
### Removed:
|
### Removed:
|
||||||
|
|
||||||
- Some methods on `Files` were for internal use only but they had a
|
- Some methods on `Files` were for internal use only but they had a
|
||||||
public API, they were modified to private.
|
public API, they were modified to private.
|
||||||
|
|
||||||
## 0.1.0
|
## 0.1.0
|
||||||
|
|
||||||
### Added:
|
### Added:
|
||||||
|
|
||||||
- `SHA-256`-based cache-buster
|
- `SHA-256`-based cache-buster
|
||||||
- runtime filemap loading
|
- runtime filemap loading
|
||||||
|
|
|
@ -13,7 +13,6 @@ fn main() {
|
||||||
.source("./static/cachable/")
|
.source("./static/cachable/")
|
||||||
.result("./dist")
|
.result("./dist")
|
||||||
.mime_types(types)
|
.mime_types(types)
|
||||||
.copy(true)
|
|
||||||
.follow_links(true)
|
.follow_links(true)
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -31,7 +31,7 @@ pub struct Files {
|
||||||
impl Files {
|
impl Files {
|
||||||
/// Load filemap in main program. Should be called from main program
|
/// Load filemap in main program. Should be called from main program
|
||||||
pub fn new(map: &str) -> Self {
|
pub fn new(map: &str) -> Self {
|
||||||
let res: Files = serde_json::from_str(&map).unwrap();
|
let res: Files = serde_json::from_str(map).unwrap();
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ impl Files {
|
||||||
///
|
///
|
||||||
/// If the modified filename path is `./prod/test.randomhash.svg`, it will
|
/// If the modified filename path is `./prod/test.randomhash.svg`, it will
|
||||||
/// output `/test.randomhash.svg`. For full path, see [get_full_path][Self::get_full_path].
|
/// output `/test.randomhash.svg`. For full path, see [get_full_path][Self::get_full_path].
|
||||||
pub fn get<'a, 'b>(&'b self, path: impl AsRef<str>) -> Option<&'b str> {
|
pub fn get(&self, path: impl AsRef<str>) -> Option<&str> {
|
||||||
if let Some(path) = self.map.get(path.as_ref()) {
|
if let Some(path) = self.map.get(path.as_ref()) {
|
||||||
Some(&path[self.base_dir.len()..])
|
Some(&path[self.base_dir.len()..])
|
||||||
// Some(&path)
|
// Some(&path)
|
||||||
|
@ -52,7 +52,7 @@ impl Files {
|
||||||
///
|
///
|
||||||
/// If the modified filename path is `./prod/test.randomhash.svg`, it will
|
/// If the modified filename path is `./prod/test.randomhash.svg`, it will
|
||||||
/// output `/prod/test.randomhash.svg`. For relative path, see [get][Self::get].
|
/// output `/prod/test.randomhash.svg`. For relative path, see [get][Self::get].
|
||||||
pub fn get_full_path<'a, 'b>(&'b self, path: impl AsRef<str>) -> Option<&'b String> {
|
pub fn get_full_path(&self, path: impl AsRef<str>) -> Option<&String> {
|
||||||
self.map.get(path.as_ref())
|
self.map.get(path.as_ref())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,6 @@ mod tests {
|
||||||
.source("./dist")
|
.source("./dist")
|
||||||
.result("/tmp/prodsd2")
|
.result("/tmp/prodsd2")
|
||||||
.mime_types(types)
|
.mime_types(types)
|
||||||
.copy(true)
|
|
||||||
.follow_links(true)
|
.follow_links(true)
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -126,7 +125,6 @@ mod tests {
|
||||||
.source("./dist")
|
.source("./dist")
|
||||||
.result("/tmp/prod5")
|
.result("/tmp/prod5")
|
||||||
.mime_types(types)
|
.mime_types(types)
|
||||||
.copy(true)
|
|
||||||
.follow_links(true)
|
.follow_links(true)
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -40,7 +40,6 @@
|
||||||
//! .source("./dist")
|
//! .source("./dist")
|
||||||
//! .result("./prod")
|
//! .result("./prod")
|
||||||
//! .mime_types(types)
|
//! .mime_types(types)
|
||||||
//! .copy(true)
|
|
||||||
//! .follow_links(true)
|
//! .follow_links(true)
|
||||||
//! .build()
|
//! .build()
|
||||||
//! .unwrap();
|
//! .unwrap();
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
//! .source("./dist")
|
//! .source("./dist")
|
||||||
//! .result("./prod")
|
//! .result("./prod")
|
||||||
//! .mime_types(types)
|
//! .mime_types(types)
|
||||||
//! .copy(true)
|
|
||||||
//! .follow_links(true)
|
//! .follow_links(true)
|
||||||
//! .build()
|
//! .build()
|
||||||
//! .unwrap();
|
//! .unwrap();
|
||||||
|
@ -83,8 +82,6 @@ pub struct Buster<'a> {
|
||||||
#[builder(setter(into, strip_option), default)]
|
#[builder(setter(into, strip_option), default)]
|
||||||
/// route prefixes
|
/// route prefixes
|
||||||
prefix: Option<String>,
|
prefix: Option<String>,
|
||||||
/// copy other non-hashed files from source dire to result dir?
|
|
||||||
copy: bool,
|
|
||||||
/// follow symlinks?
|
/// follow symlinks?
|
||||||
follow_links: bool,
|
follow_links: bool,
|
||||||
/// exclude these files for hashing.
|
/// exclude these files for hashing.
|
||||||
|
@ -147,7 +144,7 @@ impl<'a> Buster<'a> {
|
||||||
let mut file_map: Files = Files::new(&self.result);
|
let mut file_map: Files = Files::new(&self.result);
|
||||||
|
|
||||||
let mut process_worker = |path: &Path| {
|
let mut process_worker = |path: &Path| {
|
||||||
let contents = Self::read_to_string(&path).unwrap();
|
let contents = Self::read_to_string(path).unwrap();
|
||||||
let hash = Self::hasher(&contents);
|
let hash = Self::hasher(&contents);
|
||||||
|
|
||||||
let get_name = |no_hash: bool| -> String {
|
let get_name = |no_hash: bool| -> String {
|
||||||
|
@ -190,25 +187,8 @@ impl<'a> Buster<'a> {
|
||||||
|
|
||||||
let new_name = get_name(no_hash_status);
|
let new_name = get_name(no_hash_status);
|
||||||
|
|
||||||
// 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);
|
self.copy(path, &new_name);
|
||||||
let (source, destination) = self.gen_map(path, &&new_name);
|
let (source, destination) = self.gen_map(path, &new_name);
|
||||||
let _ = file_map.add(
|
let _ = file_map.add(
|
||||||
source.to_str().unwrap().into(),
|
source.to_str().unwrap().into(),
|
||||||
destination.to_str().unwrap().into(),
|
destination.to_str().unwrap().into(),
|
||||||
|
@ -233,11 +213,11 @@ impl<'a> Buster<'a> {
|
||||||
panic!("couldn't resolve MIME for file: {:?}", &path)
|
panic!("couldn't resolve MIME for file: {:?}", &path)
|
||||||
});
|
});
|
||||||
if &file_mime == mime_type {
|
if &file_mime == mime_type {
|
||||||
process_worker(&path);
|
process_worker(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => process_worker(&path),
|
None => process_worker(path),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -296,7 +276,7 @@ impl<'a> Buster<'a> {
|
||||||
let entry_path = Path::new(&entry_path);
|
let entry_path = Path::new(&entry_path);
|
||||||
|
|
||||||
if entry_path.is_dir() && path != entry_path {
|
if entry_path.is_dir() && path != entry_path {
|
||||||
Self::create_dir_structure(&self, entry_path)?;
|
Self::create_dir_structure(self, entry_path)?;
|
||||||
} else if entry_path.is_dir() {
|
} else if entry_path.is_dir() {
|
||||||
let rel_location = entry_path.strip_prefix(&self.source).unwrap();
|
let rel_location = entry_path.strip_prefix(&self.source).unwrap();
|
||||||
let destination = Path::new(&self.result).join(rel_location);
|
let destination = Path::new(&self.result).join(rel_location);
|
||||||
|
@ -361,7 +341,7 @@ impl Files {
|
||||||
pub mod tests {
|
pub mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub fn cleanup(config: &Buster) {
|
pub fn cleanup(config: &Buster<'_>) {
|
||||||
let _ = fs::remove_dir_all(&config.result);
|
let _ = fs::remove_dir_all(&config.result);
|
||||||
delete_file();
|
delete_file();
|
||||||
}
|
}
|
||||||
|
@ -386,7 +366,6 @@ pub mod tests {
|
||||||
.source("./dist")
|
.source("./dist")
|
||||||
.result("/tmp/prod2i")
|
.result("/tmp/prod2i")
|
||||||
.mime_types(types)
|
.mime_types(types)
|
||||||
.copy(true)
|
|
||||||
.follow_links(true)
|
.follow_links(true)
|
||||||
.prefix("/test")
|
.prefix("/test")
|
||||||
.no_hash(vec![no_hash.clone()])
|
.no_hash(vec![no_hash.clone()])
|
||||||
|
@ -408,7 +387,6 @@ pub mod tests {
|
||||||
let config = BusterBuilder::default()
|
let config = BusterBuilder::default()
|
||||||
.source("./dist")
|
.source("./dist")
|
||||||
.result("/tmp/prod2ii")
|
.result("/tmp/prod2ii")
|
||||||
.copy(true)
|
|
||||||
.follow_links(true)
|
.follow_links(true)
|
||||||
.no_hash(vec![no_hash.clone()])
|
.no_hash(vec![no_hash.clone()])
|
||||||
.build()
|
.build()
|
||||||
|
@ -459,7 +437,6 @@ pub mod tests {
|
||||||
.source("./dist")
|
.source("./dist")
|
||||||
.result("/tmp/prod2i")
|
.result("/tmp/prod2i")
|
||||||
.mime_types(types)
|
.mime_types(types)
|
||||||
.copy(true)
|
|
||||||
.follow_links(true)
|
.follow_links(true)
|
||||||
.prefix("/test")
|
.prefix("/test")
|
||||||
.build()
|
.build()
|
||||||
|
@ -500,7 +477,6 @@ pub mod tests {
|
||||||
let config = BusterBuilder::default()
|
let config = BusterBuilder::default()
|
||||||
.source("./dist")
|
.source("./dist")
|
||||||
.result("/tmp/prodnohashextension")
|
.result("/tmp/prodnohashextension")
|
||||||
.copy(true)
|
|
||||||
.follow_links(true)
|
.follow_links(true)
|
||||||
.no_hash(no_hash.clone())
|
.no_hash(no_hash.clone())
|
||||||
.build()
|
.build()
|
||||||
|
|
Loading…
Reference in a new issue