fix(lints): apply clippy suggestions

This commit is contained in:
Orhun Parmaksız 2022-12-18 23:12:28 +03:00
parent a954676547
commit e83b8e6f4a
No known key found for this signature in database
GPG key ID: F83424824B3E4B90
4 changed files with 20 additions and 20 deletions

View file

@ -80,7 +80,7 @@ async fn main() -> IoResult<()> {
};
hotwatch
.watch(&config_path, config_watcher)
.unwrap_or_else(|_| panic!("failed to watch {:?}", config_path));
.unwrap_or_else(|_| panic!("failed to watch {config_path:?}"));
// Create a thread for cleaning up expired files.
thread::spawn(move || loop {

View file

@ -139,7 +139,7 @@ impl Paste {
.unwrap_or_default()
.to_string();
if let Some(timestamp) = expiry_date {
path.set_file_name(format!("{}.{}", file_name, timestamp));
path.set_file_name(format!("{file_name}.{timestamp}"));
}
let mut buffer = File::create(&path)?;
buffer.write_all(&self.data)?;
@ -225,7 +225,7 @@ impl Paste {
.get_path(&config.server.upload_path)
.join(&file_name);
if let Some(timestamp) = expiry_date {
path.set_file_name(format!("{}.{}", file_name, timestamp));
path.set_file_name(format!("{file_name}.{timestamp}"));
}
fs::write(&path, url.to_string())?;
Ok(file_name)
@ -303,7 +303,7 @@ mod tests {
let file_name = paste.store_file("test.file", Some(expiry_date), &config)?;
let file_path = PasteType::Oneshot
.get_path(&config.server.upload_path)
.join(format!("{}.{}", file_name, expiry_date));
.join(format!("{file_name}.{expiry_date}"));
assert_eq!("test", fs::read_to_string(&file_path)?);
fs::remove_file(file_path)?;

View file

@ -454,10 +454,10 @@ mod tests {
)
.await;
assert_eq!(StatusCode::OK, response.status());
assert_body(response, &format!("http://localhost:8080/{}\n", file_name)).await?;
assert_body(response, &format!("http://localhost:8080/{file_name}\n")).await?;
let serve_request = TestRequest::get()
.uri(&format!("/{}", file_name))
.uri(&format!("/{file_name}"))
.to_request();
let response = test::call_service(&app, serve_request).await;
assert_eq!(StatusCode::OK, response.status());
@ -465,7 +465,7 @@ mod tests {
fs::remove_file(file_name)?;
let serve_request = TestRequest::get()
.uri(&format!("/{}", file_name))
.uri(&format!("/{file_name}"))
.to_request();
let response = test::call_service(&app, serve_request).await;
assert_eq!(StatusCode::NOT_FOUND, response.status());
@ -548,10 +548,10 @@ mod tests {
)
.await;
assert_eq!(StatusCode::OK, response.status());
assert_body(response, &format!("http://localhost:8080/{}\n", file_name)).await?;
assert_body(response, &format!("http://localhost:8080/{file_name}\n")).await?;
let serve_request = TestRequest::get()
.uri(&format!("/{}", file_name))
.uri(&format!("/{file_name}"))
.to_request();
let response = test::call_service(&app, serve_request).await;
assert_eq!(StatusCode::OK, response.status());
@ -560,12 +560,12 @@ mod tests {
thread::sleep(Duration::from_millis(40));
let serve_request = TestRequest::get()
.uri(&format!("/{}", file_name))
.uri(&format!("/{file_name}"))
.to_request();
let response = test::call_service(&app, serve_request).await;
assert_eq!(StatusCode::NOT_FOUND, response.status());
if let Some(glob_path) = glob(&format!("{}.[0-9]*", file_name))
if let Some(glob_path) = glob(&format!("{file_name}.[0-9]*"))
.map_err(error::ErrorInternalServerError)?
.next()
{
@ -605,10 +605,10 @@ mod tests {
)
.await;
assert_eq!(StatusCode::OK, response.status());
assert_body(response, &format!("http://localhost:8080/{}\n", file_name)).await?;
assert_body(response, &format!("http://localhost:8080/{file_name}\n")).await?;
let serve_request = TestRequest::get()
.uri(&format!("/{}", file_name))
.uri(&format!("/{file_name}"))
.to_request();
let response = test::call_service(&app, serve_request).await;
assert_eq!(StatusCode::OK, response.status());
@ -623,7 +623,7 @@ mod tests {
fs::remove_file(file_name)?;
let serve_request = TestRequest::get()
.uri(&format!("/{}", file_name))
.uri(&format!("/{file_name}"))
.to_request();
let response = test::call_service(&app, serve_request).await;
assert_eq!(StatusCode::NOT_FOUND, response.status());
@ -695,24 +695,24 @@ mod tests {
)
.await;
assert_eq!(StatusCode::OK, response.status());
assert_body(response, &format!("http://localhost:8080/{}\n", file_name)).await?;
assert_body(response, &format!("http://localhost:8080/{file_name}\n")).await?;
let serve_request = TestRequest::get()
.uri(&format!("/{}", file_name))
.uri(&format!("/{file_name}"))
.to_request();
let response = test::call_service(&app, serve_request).await;
assert_eq!(StatusCode::OK, response.status());
assert_body(response, &timestamp).await?;
let serve_request = TestRequest::get()
.uri(&format!("/{}", file_name))
.uri(&format!("/{file_name}"))
.to_request();
let response = test::call_service(&app, serve_request).await;
assert_eq!(StatusCode::NOT_FOUND, response.status());
if let Some(glob_path) = glob(
&oneshot_upload_path
.join(format!("{}.[0-9]*", file_name))
.join(format!("{file_name}.[0-9]*"))
.to_string_lossy(),
)
.map_err(error::ErrorInternalServerError)?

View file

@ -94,7 +94,7 @@ pub fn sha256_digest<R: Read>(input: R) -> Result<String, ActixError> {
.iter()
.collect::<Vec<&u8>>()
.iter()
.map(|byte| format!("{:02x}", byte))
.map(|byte| format!("{byte:02x}"))
.collect::<String>())
}
@ -148,7 +148,7 @@ mod tests {
fn test_get_expired_files() -> Result<(), ActixError> {
let current_dir = env::current_dir()?;
let expiration_time = get_system_time()?.as_millis() + 50;
let path = PathBuf::from(format!("expired.file2.{}", expiration_time));
let path = PathBuf::from(format!("expired.file2.{expiration_time}"));
fs::write(&path, String::new())?;
assert_eq!(Vec::<PathBuf>::new(), get_expired_files(&current_dir));
thread::sleep(Duration::from_millis(75));