Functions optimization
This commit is contained in:
parent
081fe28769
commit
d670d5303e
|
@ -0,0 +1,18 @@
|
|||
## CHANGELOG
|
||||
* 0.19.0 - Rust migration
|
||||
* 0.18.0 - Fixed Windows build + libcaesium 0.9.3
|
||||
* 0.17.0 - libcaesium 0.9.2
|
||||
* 0.16.0 - Using libcaesium Rust library
|
||||
* 0.15.2 - Fixed Windows -RS bug
|
||||
* 0.15.1 - Fixed rename bug on Windows + "Compressing..." message
|
||||
* 0.15.0 - Support for libcaesium 0.5.0
|
||||
* 0.14.0 - Added --quiet option
|
||||
* 0.13.1 - Bugfix
|
||||
* 0.13.0 - Bugfix
|
||||
* 0.12.1 - Bugfix
|
||||
* 0.12.0 - Resizing (experimental)
|
||||
* 0.11.0 - Fixing paths issues and dry-run option
|
||||
* 0.10.2 - Bugfixes & full Windows support
|
||||
* 0.10.1 - All features are available
|
||||
* 0.10.0 - Switched to cmake build system and libcaesium
|
||||
* 0.9.1 - Initial development stage
|
25
README.md
25
README.md
|
@ -1,12 +1,12 @@
|
|||
## Caesium CommandLineTools
|
||||
###### caesium-clt - v0.19.0 (build 20221114)
|
||||
###### caesium-clt - v0.19.0
|
||||
|
||||
###### REQUIREMENTS
|
||||
* [Rust](https://www.rust-lang.org/tools/install)
|
||||
----------
|
||||
|
||||
###### TESTED PLATFORMS
|
||||
* macOS Monterey (v12.6)
|
||||
* macOS Ventura (v13.0)
|
||||
* Ubuntu 22.04
|
||||
* Windows 10
|
||||
|
||||
|
@ -72,24 +72,3 @@ Losslessly compress ```Pictures``` folder and subfolders, located in the ```home
|
|||
```
|
||||
$ caesiumclt -q 0 -RS -o ~/output/ ~/Pictures
|
||||
```
|
||||
|
||||
----------
|
||||
|
||||
###### CHANGELOG
|
||||
* 0.19.0 - Rust migration
|
||||
* 0.18.0 - Fixed Windows build + libcaesium 0.9.3
|
||||
* 0.17.0 - libcaesium 0.9.2
|
||||
* 0.16.0 - Using libcaesium Rust library
|
||||
* 0.15.2 - Fixed Windows -RS bug
|
||||
* 0.15.1 - Fixed rename bug on Windows + "Compressing..." message
|
||||
* 0.15.0 - Support for libcaesium 0.5.0
|
||||
* 0.14.0 - Added --quiet option
|
||||
* 0.13.1 - Bugfix
|
||||
* 0.13.0 - Bugfix
|
||||
* 0.12.1 - Bugfix
|
||||
* 0.12.0 - Resizing (experimental)
|
||||
* 0.11.0 - Fixing paths issues and dry-run option
|
||||
* 0.10.2 - Bugfixes & full Windows support
|
||||
* 0.10.1 - All features are available
|
||||
* 0.10.0 - Switched to cmake build system and libcaesium
|
||||
* 0.9.1 - Initial development stage
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
## Caesium 命令行工具
|
||||
###### caesium-clt - v0.19.0 (build 20221114)
|
||||
###### caesium-clt - v0.19.0
|
||||
|
||||
###### 依赖
|
||||
* [Rust](https://www.rust-lang.org/tools/install)
|
||||
----------
|
||||
|
||||
###### 已通过测试的平台
|
||||
* macOS Monterey (v12.6)
|
||||
* macOS Ventura (v13.0)
|
||||
* Ubuntu 22.04
|
||||
* Windows 10
|
||||
|
||||
|
@ -71,24 +71,3 @@ $ caesiumclt -q 0 -R -o ~/output/ ~/Pictures
|
|||
```
|
||||
$ caesiumclt -q 0 -RS -o ~/output/ ~/Pictures
|
||||
```
|
||||
|
||||
----------
|
||||
|
||||
###### 变更日志
|
||||
* 0.19.0 - Rust migration
|
||||
* 0.18.0 - Fixed Windows build + libcaesium 0.9.3
|
||||
* 0.17.0 - libcaesium 0.9.2
|
||||
* 0.16.0 - Using libcaesium Rust library
|
||||
* 0.15.2 - Fixed Windows -RS bug
|
||||
* 0.15.1 - Fixed rename bug on Windows + "Compressing..." message
|
||||
* 0.15.0 - Support for libcaesium 0.5.0
|
||||
* 0.14.0 - Added --quiet option
|
||||
* 0.13.1 - Bugfix
|
||||
* 0.13.0 - Bugfix
|
||||
* 0.12.1 - Bugfix
|
||||
* 0.12.0 - Resizing (experimental)
|
||||
* 0.11.0 - Fixing paths issues and dry-run option
|
||||
* 0.10.2 - Bugfixes & full Windows support
|
||||
* 0.10.1 - All features are available
|
||||
* 0.10.0 - Switched to cmake build system and libcaesium
|
||||
* 0.9.1 - Initial development stage
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use std::path::PathBuf;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::time::Duration;
|
||||
|
||||
use indicatif::ProgressBar;
|
||||
use indicatif::ProgressStyle;
|
||||
use walkdir::WalkDir;
|
||||
|
||||
pub fn is_filetype_supported(path: &PathBuf) -> bool {
|
||||
pub fn is_filetype_supported(path: &Path) -> bool {
|
||||
let file_path = match path.to_str() {
|
||||
None => return false,
|
||||
Some(p) => p
|
||||
|
@ -20,7 +20,7 @@ pub fn is_filetype_supported(path: &PathBuf) -> bool {
|
|||
}
|
||||
|
||||
|
||||
fn is_valid(entry: &PathBuf) -> bool {
|
||||
fn is_valid(entry: &Path) -> bool {
|
||||
entry.exists() && entry.is_file() && is_filetype_supported(entry)
|
||||
}
|
||||
|
||||
|
@ -39,17 +39,11 @@ pub fn scanfiles(args: Vec<PathBuf>, recursive: bool) -> (PathBuf, Vec<PathBuf>)
|
|||
for entry in walk_dir.into_iter().filter_map(|e| e.ok()) {
|
||||
let path = entry.into_path();
|
||||
if is_valid(&path) {
|
||||
if let Ok(ap) = path.canonicalize() {
|
||||
base_path = compute_base_folder(&base_path, &ap);
|
||||
files.push(ap);
|
||||
}
|
||||
base_path = canonicalize_and_push(&path, base_path, &mut files);
|
||||
}
|
||||
}
|
||||
} else if is_valid(&input) {
|
||||
if let Ok(ap) = input.canonicalize() {
|
||||
base_path = compute_base_folder(&base_path, &ap);
|
||||
files.push(ap);
|
||||
}
|
||||
base_path = canonicalize_and_push(&input, base_path, &mut files);
|
||||
}
|
||||
|
||||
progress_bar.tick();
|
||||
|
@ -60,16 +54,25 @@ pub fn scanfiles(args: Vec<PathBuf>, recursive: bool) -> (PathBuf, Vec<PathBuf>)
|
|||
(base_path, files)
|
||||
}
|
||||
|
||||
fn compute_base_folder(base_folder: &PathBuf, new_path: &PathBuf) -> PathBuf {
|
||||
fn canonicalize_and_push(path: &Path, mut base_path: PathBuf, files: &mut Vec<PathBuf>) -> PathBuf {
|
||||
if let Ok(ap) = path.canonicalize() {
|
||||
base_path = compute_base_folder(&base_path, &ap);
|
||||
files.push(ap);
|
||||
}
|
||||
|
||||
base_path
|
||||
}
|
||||
|
||||
fn compute_base_folder(base_folder: &Path, new_path: &Path) -> PathBuf {
|
||||
if base_folder.parent().is_none() {
|
||||
return if new_path.is_dir() {
|
||||
new_path.clone()
|
||||
new_path.to_path_buf()
|
||||
} else {
|
||||
new_path.parent().unwrap_or(&*PathBuf::from("/")).to_path_buf()
|
||||
};
|
||||
}
|
||||
let mut folder = PathBuf::new();
|
||||
let mut new_path_folder = new_path.clone();
|
||||
let mut new_path_folder = new_path.to_path_buf();
|
||||
if new_path.is_file() {
|
||||
new_path_folder = new_path.parent().unwrap_or(&*PathBuf::from("/")).to_path_buf();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue