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:
|
||||
|
||||
- `Buster.no_hash` Option to exclude select files from processing. These
|
||||
files will be copied over without any processing for cache
|
||||
busting(i.e, no renaming)
|
||||
- `Buster.no_hash` Option to exclude select files from processing. These
|
||||
files will be copied over without any processing for cache
|
||||
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:
|
||||
|
||||
- `Files::new()` takes a `&str`: Earlier versions were using
|
||||
environment variables to pass filemap information from `build.rs`
|
||||
component to program code but this proved to be unreliable. Starting
|
||||
with `0.2.0`, `cache_buster` will write filemap to
|
||||
`CACHE_BUSTER_DATA_FILE`(`./src/cache_buster_data.json`) and the user
|
||||
is requested to read and pass the value to `File::new()`
|
||||
- `Files::new()` takes a `&str`: Earlier versions were using
|
||||
environment variables to pass filemap information from `build.rs`
|
||||
component to program code but this proved to be unreliable. Starting
|
||||
with `0.2.0`, `cache_buster` will write filemap to
|
||||
`CACHE_BUSTER_DATA_FILE`(`./src/cache_buster_data.json`) and the user
|
||||
is requested to read and pass the value to `File::new()`
|
||||
|
||||
- `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
|
||||
inside source directory is considered for processing.
|
||||
- `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
|
||||
inside source directory is considered for processing.
|
||||
|
||||
- `Files::get_full_path()` and `Files::get()` now accept `impl
|
||||
AsRef<str>` for path argument.
|
||||
- `Files::get_full_path()` and `Files::get()` now accept `impl AsRef<str>` for path argument.
|
||||
|
||||
### 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
|
||||
|
||||
### Added:
|
||||
|
||||
- Optional route prefix to `Processor`
|
||||
- Optional route prefix to `Processor`
|
||||
|
||||
### Changed:
|
||||
|
||||
- `Files::load()` became `Files::new()`
|
||||
- `Files::load()` became `Files::new()`
|
||||
|
||||
### Removed:
|
||||
|
||||
- Some methods on `Files` were for internal use only but they had a
|
||||
public API, they were modified to private.
|
||||
- Some methods on `Files` were for internal use only but they had a
|
||||
public API, they were modified to private.
|
||||
|
||||
## 0.1.0
|
||||
|
||||
### Added:
|
||||
|
||||
- `SHA-256`-based cache-buster
|
||||
- runtime filemap loading
|
||||
- `SHA-256`-based cache-buster
|
||||
- runtime filemap loading
|
||||
|
|
|
@ -13,7 +13,6 @@ fn main() {
|
|||
.source("./static/cachable/")
|
||||
.result("./dist")
|
||||
.mime_types(types)
|
||||
.copy(true)
|
||||
.follow_links(true)
|
||||
.build()
|
||||
.unwrap();
|
||||
|
|
|
@ -31,7 +31,7 @@ pub struct Files {
|
|||
impl Files {
|
||||
/// Load filemap in main program. Should be called from main program
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ impl Files {
|
|||
///
|
||||
/// 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].
|
||||
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()) {
|
||||
Some(&path[self.base_dir.len()..])
|
||||
// Some(&path)
|
||||
|
@ -52,7 +52,7 @@ impl Files {
|
|||
///
|
||||
/// If the modified filename path is `./prod/test.randomhash.svg`, it will
|
||||
/// 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())
|
||||
}
|
||||
}
|
||||
|
@ -81,7 +81,6 @@ mod tests {
|
|||
.source("./dist")
|
||||
.result("/tmp/prodsd2")
|
||||
.mime_types(types)
|
||||
.copy(true)
|
||||
.follow_links(true)
|
||||
.build()
|
||||
.unwrap();
|
||||
|
@ -126,7 +125,6 @@ mod tests {
|
|||
.source("./dist")
|
||||
.result("/tmp/prod5")
|
||||
.mime_types(types)
|
||||
.copy(true)
|
||||
.follow_links(true)
|
||||
.build()
|
||||
.unwrap();
|
||||
|
|
|
@ -40,7 +40,6 @@
|
|||
//! .source("./dist")
|
||||
//! .result("./prod")
|
||||
//! .mime_types(types)
|
||||
//! .copy(true)
|
||||
//! .follow_links(true)
|
||||
//! .build()
|
||||
//! .unwrap();
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
//! .source("./dist")
|
||||
//! .result("./prod")
|
||||
//! .mime_types(types)
|
||||
//! .copy(true)
|
||||
//! .follow_links(true)
|
||||
//! .build()
|
||||
//! .unwrap();
|
||||
|
@ -83,8 +82,6 @@ pub struct Buster<'a> {
|
|||
#[builder(setter(into, strip_option), default)]
|
||||
/// route prefixes
|
||||
prefix: Option<String>,
|
||||
/// copy other non-hashed files from source dire to result dir?
|
||||
copy: bool,
|
||||
/// follow symlinks?
|
||||
follow_links: bool,
|
||||
/// exclude these files for hashing.
|
||||
|
@ -147,7 +144,7 @@ impl<'a> Buster<'a> {
|
|||
let mut file_map: Files = Files::new(&self.result);
|
||||
|
||||
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 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 = 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 (source, destination) = self.gen_map(path, &new_name);
|
||||
let _ = file_map.add(
|
||||
source.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)
|
||||
});
|
||||
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);
|
||||
|
||||
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() {
|
||||
let rel_location = entry_path.strip_prefix(&self.source).unwrap();
|
||||
let destination = Path::new(&self.result).join(rel_location);
|
||||
|
@ -361,7 +341,7 @@ impl Files {
|
|||
pub mod tests {
|
||||
use super::*;
|
||||
|
||||
pub fn cleanup(config: &Buster) {
|
||||
pub fn cleanup(config: &Buster<'_>) {
|
||||
let _ = fs::remove_dir_all(&config.result);
|
||||
delete_file();
|
||||
}
|
||||
|
@ -386,7 +366,6 @@ pub mod tests {
|
|||
.source("./dist")
|
||||
.result("/tmp/prod2i")
|
||||
.mime_types(types)
|
||||
.copy(true)
|
||||
.follow_links(true)
|
||||
.prefix("/test")
|
||||
.no_hash(vec![no_hash.clone()])
|
||||
|
@ -408,7 +387,6 @@ pub mod tests {
|
|||
let config = BusterBuilder::default()
|
||||
.source("./dist")
|
||||
.result("/tmp/prod2ii")
|
||||
.copy(true)
|
||||
.follow_links(true)
|
||||
.no_hash(vec![no_hash.clone()])
|
||||
.build()
|
||||
|
@ -459,7 +437,6 @@ pub mod tests {
|
|||
.source("./dist")
|
||||
.result("/tmp/prod2i")
|
||||
.mime_types(types)
|
||||
.copy(true)
|
||||
.follow_links(true)
|
||||
.prefix("/test")
|
||||
.build()
|
||||
|
@ -500,7 +477,6 @@ pub mod tests {
|
|||
let config = BusterBuilder::default()
|
||||
.source("./dist")
|
||||
.result("/tmp/prodnohashextension")
|
||||
.copy(true)
|
||||
.follow_links(true)
|
||||
.no_hash(no_hash.clone())
|
||||
.build()
|
||||
|
|
Loading…
Reference in a new issue