Skip to content

Commit 38c1fee

Browse files
committed
prepare for release v3.0.3
1 parent f17d14a commit 38c1fee

File tree

12 files changed

+154
-188
lines changed

12 files changed

+154
-188
lines changed

CHANGELOG.md

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,31 @@ All notable changes to this project will be documented in this file. The format
44

55
## [Released]
66

7+
## [3.0.3] - 2024-12-16
8+
- Performance optimizations
9+
- Refactoring
10+
- Update dependencies
11+
12+
### Changed
13+
- Validation improvements of download command options
14+
- filename validation => option `[-r, --rename]`
15+
- output target validation => option `[-o, --output]`
16+
<br>
17+
18+
719
## [3.0.2] - 2024-12-11
820

9-
- optimization binary size => disable dependency default features
21+
- Optimized binary size => disable dependency default features
1022
- Bug fixing when comparing hash sums
23+
- Update dependencies
1124

1225
### Changed
1326
- Improve error messages
14-
- Update dependencies
1527

1628
### Added
1729
- Validation of a given hash sum, only a valid hexadecimal digit is accepted for the comparison
30+
<br>
31+
1832

1933
## [3.0.1] - 2024-12-08
2034

@@ -25,70 +39,85 @@ All notable changes to this project will be documented in this file. The format
2539
- Refactoring
2640
<br>
2741

42+
2843
## [3.0.0] - 2024-11-08
2944

45+
- Update dependencies
46+
3047
### Changed
3148
- the ``local`` subcommand now provides two options [`--file`, `--buffer`], the file path no longer needs to be specified via a separate argument
3249
- `--file` calculate a hash sum from a local file
3350
- `--buffer` calculate a hash sum from any given byte-buffer (e.g. String)
3451
- Refactoring
35-
- Update dependencies
3652

3753
### Added
3854
- Now the following hash algorithms are available:
3955
- SHA2-224
4056
- SHA2-384
4157
<br>
4258

59+
4360
## [2.0.5] - 2024-08-22
4461

62+
- Refactoring
63+
- Update dependencies
64+
4565
### Changed
4666
- Improve user and log error messages
4767
- Now ``chunked`` file downloads are supported
48-
- Refactoring
49-
- Update dependencies
5068
<br>
5169

70+
5271
## [2.0.4] - 2024-06-11
5372

73+
- Update dependencies
74+
5475
### Changed
5576
- Improvement of the URL validation for the ``download`` command, e.g. only the protocols ``http`` and ``https`` are supported
56-
- Update dependencies
5777
<br>
5878

79+
5980
## [2.0.3] - 2024-05-13
6081

82+
- Refactoring
83+
- Update dependencies
84+
6185
### Fixed
6286
- Bug fix for extracting filename from a specified URL if the ``Content-Disposition`` header not present
6387
- In the case that the specified URL contains query parameters (URL parameters) the filename could not extract correctly
6488
- This bug is fixed in this version
89+
<br>
90+
91+
92+
## [2.0.2] - 2024-05-02
6593

66-
### Changed
6794
- Refactoring
6895
- Update dependencies
69-
<br>
7096

71-
## [2.0.2] - 2024-05-02
7297
### Added
7398
- Add a Signal handler for ``Ctrl_C``
7499

75100
### Changed
76101
- Improve user error messages
77102
- Improve debug log messages
78-
- Refactoring
79-
- Update dependencies
80103
<br>
81104

105+
82106
## [2.0.1] - 2024-04-23
107+
108+
- Update dependencies
109+
83110
### Security
84111
- Bump rustls from 0.22.2 to 0.22.4
85112
- ``rustls::ConnectionCommon::complete_io`` could fall into an infinite loop based on network input.
86-
87-
### Changed
88-
- Update dependencies
89113
<br>
90114

115+
91116
## [2.0.0] - 2024-03-02
117+
118+
- Update dependencies
119+
- Refactoring
120+
92121
### Added
93122
- Implemented a panic handler to create a `Crash-Report.log` file in case of application crashes. This file contains information about the OS metadata and the crash, aiding in debugging and issue resolution.
94123

@@ -102,14 +131,10 @@ All notable changes to this project will be documented in this file. The format
102131
- Bug fix that sometimes the correct file name could not be extracted when executing the ``Download`` command
103132
- Correctly extract filenames from redirect URLs
104133
- using the ``Content-Disposition`` HTTP-Header to extract filename
105-
106-
### Changed
107-
- Update dependencies
108-
- Refactoring
109134
<br>
110135

136+
111137
## [1.0.8] - 2023-12-12
112-
### Added
113138

114139
### Fixed
115140
- Bug fix that the absolute path was not displayed correctly under Windows
@@ -119,16 +144,20 @@ All notable changes to this project will be documented in this file. The format
119144
- improvement of error messages
120145
<br>
121146

147+
122148
## [1.0.7] - 2023-12-10
123-
### Changed
149+
124150
- Update dependencies
125151
- Refactoring
152+
153+
### Changed
126154
- Improvement of the code base
127155
- Improvement of the user messages
128156
- Improvement of error handling - use [color-eyre](https://crates.io/crates/color-eyre) as error report handler
129157
- Add a new CLI-Option [-r, --rename] for the ``download`` command -> you can now specify a new file name for the file to be downloaded
130158
<br>
131159

160+
132161
## [Unreleased]
133162

134163
## [1.0.6] - 2023-10-18

Cargo.lock

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "hashguard"
3-
version = "3.0.2"
3+
version = "3.0.3"
44
edition = "2021"
55
description = "Command-Line tool for ensuring the integrity of files using hash sums"
66
authors = ["javaLux"]
@@ -20,7 +20,6 @@ clap = { version = "4.5.23", features = ["derive", "cargo", "string"] }
2020
color-eyre = "0.6.3"
2121
ctrlc = "3.4.5"
2222
indicatif = "0.17.9"
23-
lazy_static = "1.5.0"
2423
log = "0.4.22"
2524
os_info = { version = "3.9.0", default-features = false }
2625
output-coloring = "0.1.0"

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2024 javaLux
3+
Copyright (c) 2025 javaLux
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

src/app.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
use clap::ValueEnum;
22
use color_eyre::eyre::Result;
3-
use std::{
4-
path::PathBuf,
5-
sync::{
6-
atomic::{AtomicBool, Ordering},
7-
Arc,
8-
},
9-
};
3+
use std::path::PathBuf;
104

115
use crate::{panic_handling::PanicReport, utils};
126

@@ -18,11 +12,6 @@ pub const APP_INTERRUPTED_MSG: &str = concat!(
1812
" was interrupted by user..."
1913
);
2014

21-
// App state -> controlled by the CtrlC-Handler
22-
lazy_static! {
23-
pub static ref APP_SHOULD_RUN: Arc<AtomicBool> = Arc::new(AtomicBool::new(true));
24-
}
25-
2615
/// Represents the possible application log level
2716
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
2817
pub enum LogLevel {
@@ -112,14 +101,26 @@ pub fn initialize_logging(log_level: Option<LogLevel>) -> Result<()> {
112101
Ok(())
113102
}
114103

115-
/// Register the application signal handler for Ctrl-C
104+
/// Register the application signal handler.<br>
105+
/// Listens for a termination signal (e.g., `Ctrl+C`) in a background thread to handle user-initiated<br>
106+
/// interruptions gracefully. If interrupted, the application will log the interruption and exit.
116107
pub fn set_ctrl_c_handler() -> Result<()> {
117-
let ctr_c_command = || APP_SHOULD_RUN.store(false, Ordering::SeqCst);
118-
match ctrlc::set_handler(ctr_c_command) {
108+
let exit_cmd = || {
109+
log::debug!("{} was interrupted by user...", APP_NAME);
110+
println!("{}", APP_INTERRUPTED_MSG);
111+
// terminate app
112+
std::process::exit(1);
113+
};
114+
115+
match ctrlc::set_handler(exit_cmd) {
119116
Ok(_) => Ok(()),
120-
Err(handler_err) => Err(color_eyre::eyre::eyre!(handler_err)),
117+
Err(handler_err) => Err(color_eyre::eyre::eyre!(format!(
118+
"Failed to set Ctrl-C signal handler - {:?}",
119+
handler_err
120+
))),
121121
}
122122
}
123+
123124
/// Initializes the verbosity level for the Rust log output based on the specified LogLevel.
124125
///
125126
/// If the provided log level is `LogLevel::Debug`, this function sets the environment

src/cli.rs

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use clap::{Args, Parser, Subcommand};
44

55
use crate::{
66
app::{version, LogLevel},
7+
commands, filename_handling, os_specifics, utils,
78
verify::Algorithm,
89
};
910

@@ -35,7 +36,7 @@ pub struct DownloadArgs {
3536
/// URL to be used for download the file [required]
3637
pub url: String,
3738

38-
/// Origin hash sum of the file [optional]
39+
/// Origin hash sum [optional]
3940
pub hash_sum: Option<String>,
4041

4142
#[arg(
@@ -51,15 +52,17 @@ pub struct DownloadArgs {
5152
short,
5253
long,
5354
help = "A custom path for the file to be saved (Default is the user download folder)",
54-
value_name = "DIR"
55+
value_name = "DIR",
56+
value_parser = validate_output_target
5557
)]
5658
pub output: Option<PathBuf>,
5759

5860
#[arg(
5961
short,
6062
long,
6163
help = "Rename the file to be downloaded",
62-
value_name = "FILE"
64+
value_name = "FILE",
65+
value_parser = check_file_name
6366
)]
6467
pub rename: Option<String>,
6568
}
@@ -71,7 +74,8 @@ pub struct LocalArgs {
7174
long,
7275
conflicts_with = "buffer",
7376
help = "Path to a file/dir for which the hash sum will be calculated",
74-
value_name = "PATH"
77+
value_name = "PATH",
78+
value_parser = validate_hash_target
7579
)]
7680
pub path: Option<PathBuf>,
7781

@@ -84,7 +88,7 @@ pub struct LocalArgs {
8488
)]
8589
pub buffer: Option<String>,
8690

87-
/// Origin hash sum of the file [optional]
91+
/// Origin hash sum [optional]
8892
pub hash_sum: Option<String>,
8993

9094
#[arg(
@@ -96,3 +100,41 @@ pub struct LocalArgs {
96100
)]
97101
pub algorithm: Algorithm,
98102
}
103+
104+
/// Helper function to validate the option [-o, -output] of the download command
105+
fn validate_output_target(target: &str) -> Result<PathBuf, String> {
106+
let path = PathBuf::from(target);
107+
if !path.is_dir() {
108+
let cmd_err = commands::CommandError::OutputTargetInvalid(utils::get_absolute_path(&path))
109+
.to_string();
110+
Err(cmd_err)
111+
} else {
112+
Ok(path)
113+
}
114+
}
115+
116+
/// Helper function to validate the option [-r, -rename] of the download command
117+
fn check_file_name(filename: &str) -> Result<String, String> {
118+
// we can use safely `unwrap` because the os type was checked before parsing the cli arguments
119+
let os_type = os_specifics::get_os().unwrap();
120+
match filename_handling::validate_filename(&os_type, filename) {
121+
Ok(_) => Ok(filename.to_string()),
122+
Err(validate_err) => {
123+
let cmd_err =
124+
commands::CommandError::InvalidFilename(validate_err.to_string()).to_string();
125+
Err(cmd_err)
126+
}
127+
}
128+
}
129+
130+
/// Helper function to validate option [-p, -path] of the local command
131+
fn validate_hash_target(target: &str) -> Result<PathBuf, String> {
132+
let path = PathBuf::from(target);
133+
if !path.exists() {
134+
let cmd_err =
135+
commands::CommandError::PathNotExist(utils::get_absolute_path(&path)).to_string();
136+
Err(cmd_err)
137+
} else {
138+
Ok(path)
139+
}
140+
}

src/color_templates.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use output_coloring::*;
22

33
/// The templates for colored terminal output
4-
5-
// These templates using a certain background color
64
pub const INFO_TEMPLATE: ColoredTemplate = ColoredTemplate {
75
ft_color: Color::White,
86
bg_color: Some(Color::Green),

0 commit comments

Comments
 (0)