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 hotwatch
.watch(&config_path, config_watcher) .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. // Create a thread for cleaning up expired files.
thread::spawn(move || loop { thread::spawn(move || loop {

View File

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

View File

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

View File

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