Browse Source

Clippy

master
Adrian Heine 2 years ago
parent
commit
4eeb280f0d
  1. 6
      src/async_utils.rs
  2. 7
      src/build.rs
  3. 4
      src/builder.rs
  4. 10
      src/command_runner.rs
  5. 1
      src/lib.rs
  6. 6
      src/locator.rs
  7. 3
      src/loggers.rs
  8. 2
      src/resources/mod.rs
  9. 7
      src/setup/setup.rs
  10. 9
      src/symbols/git/checkout.rs
  11. 2
      src/symbols/mariadb/database.rs
  12. 2
      src/symbols/mariadb/dump.rs
  13. 2
      src/symbols/mariadb/user.rs
  14. 2
      src/symbols/npm.rs
  15. 4
      src/symbols/postgresql/database.rs
  16. 2
      src/symbols/saved_directory.rs
  17. 2
      src/symbols/systemd/user_service.rs
  18. 2
      src/symbols/wordpress/plugin.rs
  19. 6
      src/symbols/wordpress/translation.rs
  20. 5
      src/templates/nginx/server.rs
  21. 4
      tests/file.rs

6
src/async_utils.rs

@ -36,7 +36,7 @@ impl Future for TimerFuture {
type Output = ();
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let mut state = self.state.lock().unwrap();
if let State::Completed = *state {
if matches!(*state, State::Completed) {
return Poll::Ready(());
}
@ -84,10 +84,10 @@ mod test {
loop {
futures_util::select! {
_ = sleep => {},
_ = ok => assert!((Instant::now() - start).as_millis() < 100),
_ = ok => assert!(start.elapsed().as_millis() < 100),
complete => break,
}
}
})
});
}
}

7
src/build.rs

@ -15,13 +15,12 @@ pub fn create_static_output(
.to_str()
.ok_or("Filename is not valid unicode")?
.to_uppercase();
let content = String::from_utf8(read_file(&source_path)?)?;
let content = String::from_utf8(read_file(source_path)?)?;
let fence = content.chars().filter(|&c| c == '#').collect::<String>() + "#";
writeln!(
target,
"pub const {}: &str = r{1}\"{2}\"{1};",
const_name, fence, content
"pub const {const_name}: &str = r{fence}\"{content}\"{fence};"
)?;
Ok(())
}
@ -39,7 +38,7 @@ pub fn create_static_output_files(
}
Err(err) => {
if err.kind() != NotFound {
return Err(format!("Unexpected error: {}", err).into());
return Err(format!("Unexpected error: {err}").into());
}
}
}

4
src/builder.rs

@ -282,7 +282,7 @@ impl<D: Clone + Display, P: AsRef<Path>, C: Clone + Into<PhpFpmPoolConfig>>
&resource.0,
cert,
key,
nginx::php_snippet(resource.2, &pool.0, &resource.1) + &resource.3,
nginx::php_snippet(resource.2, pool.0, &resource.1) + &resource.3,
challenges_snippet_path,
),
),
@ -428,7 +428,7 @@ impl<D: Clone> ImplementationBuilder<PhpFpmPool<D>> for DefaultBuilder {
(
FileSymbol::new(
conf_path.clone().into(),
php_fpm_pool_config(&user_name.0, &socket_path, &resource.1),
php_fpm_pool_config(&user_name.0, socket_path, &resource.1),
),
ReloadServiceSymbol::new(StdCommandRunner, service_name.0.clone()),
)

10
src/command_runner.rs

@ -82,8 +82,8 @@ pub struct SetuidCommandRunner<U: AsRef<str>> {
user_name: U,
}
impl<'a, U: AsRef<str>> SetuidCommandRunner<U> {
pub fn new(user_name: U) -> Self {
impl<U: AsRef<str>> SetuidCommandRunner<U> {
pub const fn new(user_name: U) -> Self {
Self { user_name }
}
}
@ -123,7 +123,7 @@ impl<U: AsRef<str>> CommandRunner for SetuidCommandRunner<U> {
.expect("User does not exist")
.uid();
let set_home = TempSetEnv::new("HOME", format!("/home/{}", self.user_name.as_ref()));
let set_dbus = TempSetEnv::new("XDG_RUNTIME_DIR", format!("/run/user/{}", uid));
let set_dbus = TempSetEnv::new("XDG_RUNTIME_DIR", format!("/run/user/{uid}"));
//println!("{} {:?}", program, args);
let mut child = Command::new(program)
.args(args)
@ -167,10 +167,10 @@ mod test {
loop {
futures_util::select! {
_ = res => {},
_ = ps => assert!((Instant::now() - start).as_millis() < 1000),
_ = ps => assert!(start.elapsed().as_millis() < 1000),
complete => break,
}
}
})
});
}
}

1
src/lib.rs

@ -21,6 +21,7 @@
clippy::cargo_common_metadata,
clippy::future_not_send,
clippy::missing_errors_doc,
clippy::missing_panics_doc,
clippy::module_name_repetitions,
rustdoc::all,
missing_docs,

6
src/locator.rs

@ -37,7 +37,7 @@ pub trait Policy {
#[must_use]
fn path_for_data(name: impl Display) -> PathBuf {
Path::new("/root/data").join(format!("_{}", name))
Path::new("/root/data").join(format!("_{name}"))
}
}
@ -121,7 +121,7 @@ impl<P, D: AsRef<str>> ResourceLocator<KeyAndCertBundle<D>> for DefaultLocator<P
}
}
impl<'a, POLICY, P: AsRef<Path>> ResourceLocator<File<P>> for DefaultLocator<POLICY> {
impl<POLICY, P: AsRef<Path>> ResourceLocator<File<P>> for DefaultLocator<POLICY> {
type Prerequisites = Dir<PathBuf>;
fn locate(resource: &File<P>) -> (<File<P> as Resource>::Artifact, Self::Prerequisites) {
((), Dir(resource.0.as_ref().parent().unwrap().into()))
@ -370,7 +370,7 @@ impl<D: Clone + AsRef<str>, P: Policy> ResourceLocator<PhpFpmPool<D>> for Defaul
php_version, user.0
)),
user,
ServiceNameArtifact(format!("php{}-fpm", php_version)),
ServiceNameArtifact(format!("php{php_version}-fpm")),
),
(),
)

3
src/loggers.rs

@ -8,7 +8,7 @@ use std::rc::Rc;
// 1 - Error, 2 - Warn, 3 - Info, 4 - Debug, 5 - Trace
pub type Level = usize;
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Entry<S>(pub Level, pub S);
pub trait Logger {
@ -110,6 +110,7 @@ impl StoringLogger {
Self::default()
}
#[must_use]
pub fn release(self) -> Vec<Entry<String>> {
Rc::try_unwrap(self.log).unwrap().into_inner().1
}

2
src/resources/mod.rs

@ -42,7 +42,7 @@ impl<D> Resource for KeyAndCertBundle<D> {
#[derive(Debug, Hash, PartialEq, Eq)]
pub struct File<P>(pub P, pub String);
impl<'a, P> Resource for File<P> {
impl<P> Resource for File<P> {
type Artifact = ();
}

7
src/setup/setup.rs

@ -100,7 +100,7 @@ impl<L: 'static, B: 'static, SR: 'static, Rs: Hash + Eq + 'static, As: 'static>
);
drop(resources);
let result = future.await;
result.map_err(|e| e.into())
result.map_err(std::convert::Into::into)
};
result.map(|(t, did_run)| (t.into_artifact(), did_run))
}
@ -148,7 +148,7 @@ impl<
let drain = recorder.clone();
let log = Rc::new(slog::Logger::root(
drain,
o!("resource" => format!("{:?}", resource)),
o!("resource" => format!("{resource:?}")),
));
let result = self.1.add(&log, resource, force_run).await;
@ -190,7 +190,7 @@ impl<
let drain = recorder.clone();
let log = Rc::new(slog::Logger::root(
drain,
o!("symbol" => format!("{:?}", symbol)),
o!("symbol" => format!("{symbol:?}")),
));
let result = (self.1).0.core.run_symbol(&symbol, &log, force).await;
@ -332,6 +332,7 @@ mod test {
}
}
#[allow(clippy::type_complexity)]
fn get_setup() -> (
Rc<RefCell<usize>>,
Setup<

9
src/symbols/git/checkout.rs

@ -17,7 +17,7 @@ pub struct Checkout<_C, C, P, S, B> {
phantom: PhantomData<_C>,
}
impl<C, _C, P, S, B> Checkout<_C, C, P, S, B> {
impl<_C, C, P, S, B> Checkout<_C, C, P, S, B> {
pub fn new(target: P, source: S, branch: B, command_runner: C) -> Self {
Self {
target,
@ -29,7 +29,7 @@ impl<C, _C, P, S, B> Checkout<_C, C, P, S, B> {
}
}
impl<C: CommandRunner, _C: Borrow<C>, P: AsRef<Path>, S, B> Checkout<C, _C, P, S, B> {
impl<_C: CommandRunner, C: Borrow<_C>, P: AsRef<Path>, S, B> Checkout<_C, C, P, S, B> {
async fn run_git(&self, args: &[impl AsRef<OsStr>]) -> Result<Vec<u8>, Box<dyn Error>> {
let mut new_args = Vec::with_capacity(args.len() + 2);
new_args.extend_from_slice(args!["-C", self.target.as_ref()]);
@ -43,8 +43,8 @@ impl<C: CommandRunner, _C: Borrow<C>, P: AsRef<Path>, S, B> Checkout<C, _C, P, S
}
#[async_trait(?Send)]
impl<C: CommandRunner, _C: Borrow<C>, P: AsRef<Path>, S: AsRef<str>, B: AsRef<str>> Symbol
for Checkout<C, _C, P, S, B>
impl<_C: CommandRunner, C: Borrow<_C>, P: AsRef<Path>, S: AsRef<str>, B: AsRef<str>> Symbol
for Checkout<_C, C, P, S, B>
{
async fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
if !self.target.as_ref().exists() {
@ -146,7 +146,6 @@ mod test {
["-C", "target", "rev-list", "-1", "HEAD"],
]
);
drop(first_two_args);
assert_eq!(args[2], ["-C", "target", "rev-list", "-1", "FETCH_HEAD"]);
assert!((end - start).as_millis() >= 100);

2
src/symbols/mariadb/database.rs

@ -12,7 +12,7 @@ pub struct Database<'a, D, S, C> {
}
impl<'a, D, S, C: CommandRunner> Database<'a, D, S, C> {
pub fn new(db_name: D, seed_file: S, command_runner: &'a C) -> Self {
pub const fn new(db_name: D, seed_file: S, command_runner: &'a C) -> Self {
Self {
db_name,
seed_file,

2
src/symbols/mariadb/dump.rs

@ -13,7 +13,7 @@ pub struct Dump<'a, N, C, S> {
}
impl<'a, N, C: CommandRunner, S> Dump<'a, N, C, S> {
pub fn new(db_name: N, storage: S, command_runner: &'a C) -> Self {
pub const fn new(db_name: N, storage: S, command_runner: &'a C) -> Self {
Self {
db_name,
storage,

2
src/symbols/mariadb/user.rs

@ -10,7 +10,7 @@ pub struct User<'a, U, C> {
}
impl<'a, U: AsRef<str>, C: CommandRunner> User<'a, U, C> {
pub fn new(user_name: U, command_runner: &'a C) -> Self {
pub const fn new(user_name: U, command_runner: &'a C) -> Self {
Self {
user_name,
command_runner,

2
src/symbols/npm.rs

@ -12,7 +12,7 @@ pub struct Install<'a, T: AsRef<Path>, C: CommandRunner> {
}
impl<'a, T: AsRef<Path>, C: CommandRunner> Install<'a, T, C> {
pub fn new(target: T, command_runner: &'a C) -> Self {
pub const fn new(target: T, command_runner: &'a C) -> Self {
Self {
target,
command_runner,

4
src/symbols/postgresql/database.rs

@ -12,7 +12,7 @@ pub struct PostgreSQLDatabase<'a, N: AsRef<str>, S: AsRef<str>, C: CommandRunner
}
impl<'a, N: AsRef<str>, S: AsRef<str>, C: CommandRunner> PostgreSQLDatabase<'a, N, S, C> {
pub fn new(name: N, seed_file: S, command_runner: &'a C) -> Self {
pub const fn new(name: N, seed_file: S, command_runner: &'a C) -> Self {
PostgreSQLDatabase {
name,
seed_file,
@ -25,7 +25,7 @@ impl<'a, N: AsRef<str>, S: AsRef<str>, C: CommandRunner> PostgreSQLDatabase<'a,
.command_runner
.get_output(
"su",
args!["-", "postgres", "-c", format!("psql -t -c \"{}\"", sql)],
args!["-", "postgres", "-c", format!("psql -t -c \"{sql}\"")],
)
.await?;
Ok(String::from_utf8(b)?)

2
src/symbols/saved_directory.rs

@ -10,7 +10,7 @@ use std::marker::PhantomData;
use std::path::Path;
use std::str::FromStr;
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq)]
pub enum StorageDirection {
Load,
Store,

2
src/symbols/systemd/user_service.rs

@ -15,7 +15,7 @@ pub struct UserService<'a, S: AsRef<Path>, U: AsRef<str>> {
}
impl<S: AsRef<Path>, U: AsRef<str>> UserService<'static, S, U> {
pub fn new(socket_path: S, user_name: U, service_name: &'static str) -> Self {
pub const fn new(socket_path: S, user_name: U, service_name: &'static str) -> Self {
Self {
socket_path,
service_name,

2
src/symbols/wordpress/plugin.rs

@ -16,7 +16,7 @@ pub struct Plugin<'a, P, N, R> {
}
impl<'a, P: AsRef<Path>, N: AsRef<str>, R: CommandRunner> Plugin<'a, P, N, R> {
pub fn new(base: P, name: N, command_runner: &'a R) -> Self {
pub const fn new(base: P, name: N, command_runner: &'a R) -> Self {
Self {
base,
name,

6
src/symbols/wordpress/translation.rs

@ -19,7 +19,7 @@ pub struct Translation<'a, C, D, R> {
}
impl<'a, D, C: AsRef<str>, R: CommandRunner> Translation<'a, C, D, R> {
pub fn new(path: D, version: &'a str, locale: C, command_runner: &'a R) -> Self {
pub const fn new(path: D, version: &'a str, locale: C, command_runner: &'a R) -> Self {
Self {
path,
version,
@ -33,7 +33,7 @@ impl<C: AsRef<str>, D: AsRef<Path>, R: CommandRunner> Translation<'_, C, D, R> {
fn get_pairs(&self) -> Vec<(String, PathBuf)> {
let version_x = self
.version
.trim_end_matches(|c: char| c.is_digit(10))
.trim_end_matches(|c: char| c.is_ascii_digit())
.to_owned()
+ "x";
let locale = self.locale.as_ref();
@ -51,7 +51,7 @@ impl<C: AsRef<str>, D: AsRef<Path>, R: CommandRunner> Translation<'_, C, D, R> {
] {
for format in &["po", "mo"] {
res.push((
format!("https://translate.wordpress.org/projects/wp/{}/{}{}/default/export-translations?format={}", version_x, in_slug, path_locale, format),
format!("https://translate.wordpress.org/projects/wp/{version_x}/{in_slug}{path_locale}/default/export-translations?format={format}"),
[self.path.as_ref(), format!("{}{}.{}", out_slug, self.locale.as_ref(), format).as_ref()].iter().collect()
));
}

5
src/templates/nginx/server.rs

@ -78,9 +78,8 @@ pub fn php_snippet<SOCKET: AsRef<Path>, STATIC: AsRef<Path>>(
pub fn redir_snippet(target: &str) -> String {
format!(
"location / {{
return 301 $scheme://{}$request_uri;
}}",
target
return 301 $scheme://{target}$request_uri;
}}"
)
}

4
tests/file.rs

@ -98,7 +98,7 @@ fn may_not_read_file() {
#[test]
fn may_not_create_file() {
let symbol = get_symbol(&Path::new("/proc/somefile"));
let symbol = get_symbol(Path::new("/proc/somefile"));
run(async {
// Could also return an error
@ -109,7 +109,7 @@ fn may_not_create_file() {
#[test]
fn directory_missing() {
let symbol = get_symbol(&Path::new("/nonexisting"));
let symbol = get_symbol(Path::new("/nonexisting"));
run(async {
// Could also return an error

Loading…
Cancel
Save