Skip to content

Commit c31f960

Browse files
committed
clippy
1 parent 8e203a8 commit c31f960

File tree

14 files changed

+77
-68
lines changed

14 files changed

+77
-68
lines changed

src/app_config.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,17 @@ impl AppConfig {
3434
config_file
3535
));
3636
}
37-
log::debug!("Loading configuration from file: {:?}", config_file);
37+
log::debug!("Loading configuration from file: {config_file:?}");
3838
load_from_file(config_file)?
3939
} else if let Some(config_dir) = &cli.config_dir {
40-
log::debug!("Loading configuration from directory: {:?}", config_dir);
40+
log::debug!("Loading configuration from directory: {config_dir:?}");
4141
load_from_directory(config_dir)?
4242
} else {
4343
log::debug!("Loading configuration from environment");
4444
load_from_env()?
4545
};
4646
if let Some(web_root) = &cli.web_root {
47-
log::debug!(
48-
"Setting web root to value from the command line: {:?}",
49-
web_root
50-
);
47+
log::debug!("Setting web root to value from the command line: {web_root:?}");
5148
config.web_root.clone_from(web_root);
5249
}
5350
if let Some(config_dir) = &cli.config_dir {
@@ -82,7 +79,7 @@ impl AppConfig {
8279
.validate()
8380
.context("The provided configuration is invalid")?;
8481

85-
log::debug!("Loaded configuration: {:#?}", config);
82+
log::debug!("Loaded configuration: {config:#?}");
8683

8784
Ok(config)
8885
}
@@ -305,7 +302,7 @@ fn cannonicalize_if_possible(path: &std::path::Path) -> PathBuf {
305302
/// This should be called only once at the start of the program.
306303
pub fn load_from_directory(directory: &Path) -> anyhow::Result<AppConfig> {
307304
let cannonical = cannonicalize_if_possible(directory);
308-
log::debug!("Loading configuration from {:?}", cannonical);
305+
log::debug!("Loading configuration from {cannonical:?}");
309306
let config_file = directory.join("sqlpage");
310307
let mut app_config = load_from_file(&config_file)?;
311308
app_config.configuration_directory = directory.into();
@@ -314,7 +311,7 @@ pub fn load_from_directory(directory: &Path) -> anyhow::Result<AppConfig> {
314311

315312
/// Parses and loads the configuration from the given file.
316313
pub fn load_from_file(config_file: &Path) -> anyhow::Result<AppConfig> {
317-
log::debug!("Loading configuration from file: {:?}", config_file);
314+
log::debug!("Loading configuration from file: {config_file:?}");
318315
let config = Config::builder()
319316
.add_source(config::File::from(config_file).required(false))
320317
.add_source(env_config())
@@ -450,7 +447,7 @@ fn create_default_database(configuration_directory: &Path) -> String {
450447
}
451448
}
452449

453-
log::warn!("No DATABASE_URL provided, and {:?} is not writeable. Using a temporary in-memory SQLite database. All the data created will be lost when this server shuts down.", configuration_directory);
450+
log::warn!("No DATABASE_URL provided, and {configuration_directory:?} is not writeable. Using a temporary in-memory SQLite database. All the data created will be lost when this server shuts down.");
454451
prefix + ":memory:?cache=shared"
455452
}
456453

@@ -477,7 +474,7 @@ fn default_database_connection_acquire_timeout_seconds() -> f64 {
477474

478475
fn default_web_root() -> PathBuf {
479476
std::env::current_dir().unwrap_or_else(|e| {
480-
log::error!("Unable to get current directory: {}", e);
477+
log::error!("Unable to get current directory: {e}");
481478
PathBuf::from(&std::path::Component::CurDir)
482479
})
483480
}

src/file_cache.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ impl<T: AsyncFromStrWithState> FileCache<T> {
117117
path: &Path,
118118
privileged: bool,
119119
) -> anyhow::Result<Arc<T>> {
120-
log::trace!("Attempting to get from cache {:?}", path);
120+
log::trace!("Attempting to get from cache {path:?}");
121121
if let Some(cached) = self.cache.read().await.get(path) {
122122
if app_state.config.environment.is_prod() && !cached.needs_check() {
123-
log::trace!("Cache answer without filesystem lookup for {:?}", path);
123+
log::trace!("Cache answer without filesystem lookup for {path:?}");
124124
return Ok(Arc::clone(&cached.content));
125125
}
126126
match app_state
@@ -129,7 +129,7 @@ impl<T: AsyncFromStrWithState> FileCache<T> {
129129
.await
130130
{
131131
Ok(false) => {
132-
log::trace!("Cache answer with filesystem metadata read for {:?}", path);
132+
log::trace!("Cache answer with filesystem metadata read for {path:?}");
133133
cached.update_check_time();
134134
return Ok(Arc::clone(&cached.content));
135135
}
@@ -138,7 +138,7 @@ impl<T: AsyncFromStrWithState> FileCache<T> {
138138
}
139139
}
140140
// Read lock is released
141-
log::trace!("Loading and parsing {:?}", path);
141+
log::trace!("Loading and parsing {path:?}");
142142
let file_contents = app_state
143143
.file_system
144144
.read_to_string(app_state, path, privileged)
@@ -170,19 +170,19 @@ impl<T: AsyncFromStrWithState> FileCache<T> {
170170
match parsed {
171171
Ok(value) => {
172172
let new_val = Arc::clone(&value.content);
173-
log::trace!("Writing to cache {:?}", path);
173+
log::trace!("Writing to cache {path:?}");
174174
self.cache.write().await.insert(PathBuf::from(path), value);
175-
log::trace!("Done writing to cache {:?}", path);
176-
log::trace!("{:?} loaded in cache", path);
175+
log::trace!("Done writing to cache {path:?}");
176+
log::trace!("{path:?} loaded in cache");
177177
Ok(new_val)
178178
}
179179
Err(e) => {
180180
log::trace!(
181181
"Evicting {path:?} from the cache because the following error occurred: {e}"
182182
);
183-
log::trace!("Removing from cache {:?}", path);
183+
log::trace!("Removing from cache {path:?}");
184184
self.cache.write().await.remove(path);
185-
log::trace!("Done removing from cache {:?}", path);
185+
log::trace!("Done removing from cache {path:?}");
186186
Err(e)
187187
}
188188
}

src/filesystem.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,7 @@ impl DbFsQueries {
204204
PgTimeTz::type_info().into(),
205205
<str as Type<Postgres>>::type_info().into(),
206206
];
207-
log::debug!(
208-
"Preparing the database filesystem was_modified_query: {}",
209-
was_modified_query
210-
);
207+
log::debug!("Preparing the database filesystem was_modified_query: {was_modified_query}");
211208
db.prepare_with(&was_modified_query, param_types).await
212209
}
213210

@@ -220,10 +217,7 @@ impl DbFsQueries {
220217
make_placeholder(db_kind, 1),
221218
);
222219
let param_types: &[AnyTypeInfo; 1] = &[<str as Type<Postgres>>::type_info().into()];
223-
log::debug!(
224-
"Preparing the database filesystem read_file_query: {}",
225-
read_file_query
226-
);
220+
log::debug!("Preparing the database filesystem read_file_query: {read_file_query}");
227221
db.prepare_with(&read_file_query, param_types).await
228222
}
229223

@@ -300,7 +294,7 @@ impl DbFsQueries {
300294
(path,)
301295
);
302296
let result = query.fetch_optional(&app_state.db.connection).await;
303-
log::debug!("DB File exists result: {:?}", result);
297+
log::debug!("DB File exists result: {result:?}");
304298
result
305299
.map(|result| result.is_some())
306300
.with_context(|| format!("Unable to check if {path:?} exists in the database"))

src/render.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl HeaderContext {
189189
if remove == Some(&json!(true)) || remove == Some(&json!(1)) {
190190
cookie.make_removal();
191191
self.response.cookie(cookie);
192-
log::trace!("Removing cookie {}", name);
192+
log::trace!("Removing cookie {name}");
193193
return Ok(self);
194194
}
195195

@@ -225,7 +225,7 @@ impl HeaderContext {
225225
_ => bail!("expires must be a string or a number"),
226226
}));
227227
}
228-
log::trace!("Setting cookie {}", cookie);
228+
log::trace!("Setting cookie {cookie}");
229229
self.response
230230
.append_header((header::SET_COOKIE, cookie.encoded().to_string()));
231231
Ok(self)
@@ -300,10 +300,10 @@ impl HeaderContext {
300300
let password_hash = take_object_str(&mut data, "password_hash");
301301
let password = take_object_str(&mut data, "password");
302302
if let (Some(password), Some(password_hash)) = (password, password_hash) {
303-
log::debug!("Authentication with password_hash = {:?}", password_hash);
303+
log::debug!("Authentication with password_hash = {password_hash:?}");
304304
match verify_password_async(password_hash, password).await? {
305305
Ok(()) => return Ok(PageContext::Header(self)),
306-
Err(e) => log::info!("Password didn't match: {}", e),
306+
Err(e) => log::info!("Password didn't match: {e}"),
307307
}
308308
}
309309
log::debug!("Authentication failed");
@@ -405,7 +405,7 @@ impl AnyRenderBodyContext {
405405
}
406406
}
407407
pub async fn handle_error(&mut self, error: &anyhow::Error) -> anyhow::Result<()> {
408-
log::error!("SQL error: {:?}", error);
408+
log::error!("SQL error: {error:?}");
409409
match self {
410410
AnyRenderBodyContext::Html(render_context) => render_context.handle_error(error).await,
411411
AnyRenderBodyContext::Json(json_body_renderer) => {
@@ -766,7 +766,7 @@ impl<W: std::io::Write> HtmlRenderContext<W> {
766766

767767
pub async fn handle_result_and_log<R>(&mut self, result: &anyhow::Result<R>) {
768768
if let Err(e) = self.handle_result(result).await {
769-
log::error!("{}", e);
769+
log::error!("{e}");
770770
}
771771
}
772772

@@ -838,14 +838,14 @@ impl<W: std::io::Write> HtmlRenderContext<W> {
838838
}
839839

840840
fn close_component(&mut self) -> anyhow::Result<()> {
841-
if let Some(old_component) = self.current_component.as_mut().take() {
841+
if let Some(old_component) = self.current_component.as_mut() {
842842
old_component.render_end(&mut self.writer)?;
843843
}
844844
Ok(())
845845
}
846846

847847
pub async fn close(mut self) -> W {
848-
if let Some(old_component) = self.current_component.as_mut().take() {
848+
if let Some(old_component) = self.current_component.as_mut() {
849849
let res = old_component
850850
.render_end(&mut self.writer)
851851
.map_err(|e| format_err!("Unable to render the component closing: {e}"));

src/template_helpers.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ mod tests {
588588
use handlebars::{JsonValue, PathAndJson, ScopedJson};
589589
use serde_json::Value;
590590

591-
const CONTENT_KEY: &'static str = "contents_md";
591+
const CONTENT_KEY: &str = "contents_md";
592592

593593
#[test]
594594
fn test_rfc2822_date() {
@@ -624,8 +624,8 @@ mod tests {
624624

625625
use super::*;
626626

627-
const UNSAFE_MARKUP: &'static str = "<table><tr><td>";
628-
const ESCAPED_UNSAFE_MARKUP: &'static str = "&lt;table&gt;&lt;tr&gt;&lt;td&gt;";
627+
const UNSAFE_MARKUP: &str = "<table><tr><td>";
628+
const ESCAPED_UNSAFE_MARKUP: &str = "&lt;table&gt;&lt;tr&gt;&lt;td&gt;";
629629
#[test]
630630
fn test_html_blocks_with_various_settings() {
631631
let helper = MarkdownHelper::default();
@@ -672,7 +672,7 @@ mod tests {
672672
Some(ref preset) => &as_args_with_unsafe(&content, preset)[..],
673673
};
674674

675-
match helper.call(&args) {
675+
match helper.call(args) {
676676
Ok(actual) => assert_eq!(
677677
case.expected_output.unwrap(),
678678
actual.as_str().unwrap(),

src/webserver/database/connect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ fn add_on_connection_handler(
172172
fn set_custom_connect_options(options: &mut AnyConnectOptions, config: &AppConfig) {
173173
if let Some(sqlite_options) = options.as_sqlite_mut() {
174174
for extension_name in &config.sqlite_extensions {
175-
log::info!("Loading SQLite extension: {}", extension_name);
175+
log::info!("Loading SQLite extension: {extension_name}");
176176
*sqlite_options = std::mem::take(sqlite_options).extension(extension_name.clone());
177177
}
178178
*sqlite_options = std::mem::take(sqlite_options)

src/webserver/database/execute_queries.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub fn stream_query_results_with_conn<'a>(
5353
match res {
5454
ParsedStatement::CsvImport(csv_import) => {
5555
let connection = take_connection(&request.app_state.db, db_connection).await?;
56-
log::debug!("Executing CSV import: {:?}", csv_import);
56+
log::debug!("Executing CSV import: {csv_import:?}");
5757
run_csv_import(connection, csv_import, request).await.with_context(|| format!("Failed to import the CSV file {:?} into the table {:?}", csv_import.uploaded_file, csv_import.table_name))?;
5858
},
5959
ParsedStatement::StmtWithParams(stmt) => {
@@ -269,7 +269,7 @@ fn parse_single_sql_result(
269269
DbItem::Row(super::sql_to_json::row_to_json(&r))
270270
}
271271
Ok(Either::Left(res)) => {
272-
log::debug!("Finished query with result: {:?}", res);
272+
log::debug!("Finished query with result: {res:?}");
273273
DbItem::FinishedQuery
274274
}
275275
Err(err) => {
@@ -296,7 +296,7 @@ fn debug_row(r: &AnyRow) {
296296
.unwrap();
297297
}
298298
}
299-
log::trace!("Received db row: {}", row_str);
299+
log::trace!("Received db row: {row_str}");
300300
}
301301

302302
fn clone_anyhow_err(source_file: &Path, err: &anyhow::Error) -> anyhow::Error {
@@ -313,7 +313,7 @@ async fn bind_parameters<'a>(
313313
db_connection: &mut DbConn,
314314
) -> anyhow::Result<StatementWithParams<'a>> {
315315
let sql = stmt.query.as_str();
316-
log::debug!("Preparing statement: {}", sql);
316+
log::debug!("Preparing statement: {sql}");
317317
let mut arguments = AnyArguments::default();
318318
for (param_idx, param) in stmt.params.iter().enumerate() {
319319
log::trace!("\tevaluating parameter {}: {}", param_idx + 1, param);

src/webserver/database/sql.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl ParsedSqlFile {
3232
#[must_use]
3333
pub fn new(db: &Database, sql: &str, source_path: &Path) -> ParsedSqlFile {
3434
let dialect = dialect_for_db(db.connection.any_kind());
35-
log::debug!("Parsing SQL file {:?}", source_path);
35+
log::debug!("Parsing SQL file {source_path:?}");
3636
let parsed_statements = match parse_sql(dialect.as_ref(), sql) {
3737
Ok(parsed) => parsed,
3838
Err(err) => return Self::from_err(err, source_path),
@@ -566,7 +566,7 @@ impl ParameterExtractor {
566566
db_kind,
567567
parameters: vec![],
568568
};
569-
sql_ast.visit(&mut this);
569+
let _ = sql_ast.visit(&mut this);
570570
this.parameters
571571
}
572572

src/webserver/database/sql_to_json.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ pub fn sql_to_json(row: &AnyRow, col: &sqlx::any::AnyColumn) -> Value {
2828
.take()
2929
.unwrap_or_else(|| row.try_get_raw(col.ordinal()).unwrap())
3030
});
31-
log::trace!("Decoded value: {:?}", decoded);
31+
log::trace!("Decoded value: {decoded:?}");
3232
decoded
3333
}
3434
Ok(_null) => Value::Null,
3535
Err(e) => {
36-
log::warn!("Unable to extract value from row: {:?}", e);
36+
log::warn!("Unable to extract value from row: {e:?}");
3737
Value::Null
3838
}
3939
}

src/webserver/database/sqlpage_functions/functions.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ async fn persist_uploaded_file<'a>(
424424
return Ok(None);
425425
};
426426
let file_name = uploaded_file.file_name.as_deref().unwrap_or_default();
427-
let extension = file_name.split('.').last().unwrap_or_default();
427+
let extension = file_name.split('.').next_back().unwrap_or_default();
428428
if !allowed_extensions
429429
.clone()
430430
.any(|x| x.eq_ignore_ascii_case(extension))
@@ -446,14 +446,22 @@ async fn persist_uploaded_file<'a>(
446446
tokio::fs::copy(&uploaded_file.file.path(), &target_path)
447447
.await
448448
.with_context(|| {
449-
format!("unable to copy uploaded file {field_name:?} to {target_path:?}")
449+
format!(
450+
"unable to copy uploaded file {field_name:?} to \"{}\"",
451+
target_path.display()
452+
)
450453
})?;
451454
// remove the WEB_ROOT prefix from the path, but keep the leading slash
452455
let path = "/".to_string()
453456
+ target_path
454457
.strip_prefix(web_root)?
455458
.to_str()
456-
.with_context(|| format!("unable to convert path {target_path:?} to a string"))?;
459+
.with_context(|| {
460+
format!(
461+
"unable to convert path \"{}\" to a string",
462+
target_path.display()
463+
)
464+
})?;
457465
Ok(Some(path))
458466
}
459467

@@ -497,7 +505,7 @@ async fn read_file_bytes(request: &RequestInfo, path_str: &str) -> Result<Vec<u8
497505
} else {
498506
tokio::fs::read(path)
499507
.await
500-
.with_context(|| format!("Unable to read file {path:?}"))
508+
.with_context(|| format!("Unable to read file \"{}\"", path.display()))
501509
}
502510
}
503511

@@ -609,7 +617,7 @@ async fn run_sql<'a>(
609617
use crate::webserver::database::DbItem::{Error, FinishedQuery, Row};
610618
match db_item {
611619
Row(row) => {
612-
log::debug!("run_sql: row: {:?}", row);
620+
log::debug!("run_sql: row: {row:?}");
613621
seq.serialize_element(&row)?;
614622
}
615623
FinishedQuery => log::trace!("run_sql: Finished query"),
@@ -736,7 +744,7 @@ async fn request_body(request: &RequestInfo) -> Option<String> {
736744
/// application/x-www-form-urlencoded or multipart/form-data (in this case, the body is accessible via the `post_variables` field).
737745
async fn request_body_base64(request: &RequestInfo) -> Option<String> {
738746
let raw_body = request.raw_body.as_ref()?;
739-
let mut base64_string = String::with_capacity((raw_body.len() * 4 + 2) / 3);
747+
let mut base64_string = String::with_capacity((raw_body.len() * 4).div_ceil(3));
740748
base64::Engine::encode_string(
741749
&base64::engine::general_purpose::STANDARD,
742750
raw_body,

0 commit comments

Comments
 (0)