Skip to content

Commit

Permalink
style: update rustfmt.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
llenotre committed Nov 10, 2024
1 parent 6f74df1 commit f6e8bf3
Show file tree
Hide file tree
Showing 21 changed files with 130 additions and 150 deletions.
23 changes: 11 additions & 12 deletions builder/src/build.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
//! Implementation of the package building procedure.
use crate::desc::BuildDescriptor;
use crate::WORK_DIR;
use crate::{desc::BuildDescriptor, WORK_DIR};
use anyhow::Result;
use flate2::write::GzEncoder;
use flate2::Compression;
use std::fs;
use std::fs::File;
use std::io;
use std::path::Path;
use std::path::PathBuf;
use std::process::Command;
use std::str;
use std::sync::Arc;
use flate2::{write::GzEncoder, Compression};
use std::{
fs,
fs::File,
io,
path::{Path, PathBuf},
process::Command,
str,
sync::Arc,
};

/// A build process is the operation of converting source code into an installable package.
///
Expand Down
10 changes: 5 additions & 5 deletions builder/src/desc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
use anyhow::Result;
use common::package::Package;
use serde::Deserialize;
use serde::Serialize;
use std::fs;
use std::path::Path;
use std::path::PathBuf;
use serde::{Deserialize, Serialize};
use std::{
fs,
path::{Path, PathBuf},
};

// TODO add an option to allow fetching a tarball without decompressing it?

Expand Down
15 changes: 6 additions & 9 deletions builder/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ mod build;
mod desc;
mod util;

use crate::build::BuildProcess;
use crate::util::{get_build_triplet, get_jobs_count};
use anyhow::Result;
use anyhow::{anyhow, bail};
use crate::{
build::BuildProcess,
util::{get_build_triplet, get_jobs_count},
};
use anyhow::{anyhow, bail, Result};
use common::repository::Repository;
use std::env;
use std::fs;
use std::path::PathBuf;
use std::process::exit;
use std::str;
use std::{env, fs, path::PathBuf, process::exit, str};
use tokio::runtime::Runtime;

/// The path to the work directory.
Expand Down
5 changes: 1 addition & 4 deletions builder/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
use anyhow::{anyhow, Result};
use core::str;
use std::ffi::OsStr;
use std::num::NonZeroUsize;
use std::process::Command;
use std::{env, io, thread};
use std::{env, ffi::OsStr, io, num::NonZeroUsize, process::Command, thread};

/// Default build triplet in case it cannot be retrieved.
const DEFAULT_BUILD_TRIPLET: &str = "x86_64-linux-gnu";
Expand Down
7 changes: 4 additions & 3 deletions client/src/confirm.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! This module implements a confirmation prompt.
use std::io;
use std::io::BufRead;
use std::io::Write;
use std::{
io,
io::{BufRead, Write},
};

/// Asks for confirmation. If yes, true is returned. Else, false is returned.
pub fn prompt() -> bool {
Expand Down
24 changes: 13 additions & 11 deletions client/src/install.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
//! This module handles package installation.
use crate::confirm;
use common::anyhow::bail;
use common::anyhow::Result;
use common::package::Package;
use common::repository;
use common::repository::Repository;
use common::Environment;
use std::collections::HashMap;
use std::path::PathBuf;

#[cfg(feature = "network")]
use common::repository::remote::Remote;
use common::{
anyhow::{bail, Result},
package::Package,
repository,
repository::Repository,
Environment,
};
use std::{collections::HashMap, path::PathBuf};

// TODO Clean
/// Installs the given list of packages.
Expand Down Expand Up @@ -65,8 +64,11 @@ pub async fn install(
let res = package.resolve_dependencies(
&mut total_packages,
&mut |name, version_constraint| {
let res =
repository::get_package_with_constraint(&repos, name, Some(version_constraint));
let res = repository::get_package_with_constraint(
&repos,
name,
Some(version_constraint),
);
let pkg = match res {
Ok(p) => p,
Err(e) => {
Expand Down
20 changes: 11 additions & 9 deletions client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@ mod remove;
#[cfg(feature = "network")]
mod update;

use common::anyhow::anyhow;
use common::anyhow::Result;
use common::Environment;
#[cfg(feature = "network")]
use common::repository::remote::Remote;
use common::{
anyhow::{anyhow, Result},
Environment,
};
use install::install;
use remove::remove;
use std::env;
use std::path::{Path, PathBuf};
use std::process::exit;
use std::{
env,
path::{Path, PathBuf},
process::exit,
};
use tokio::runtime::Runtime;

#[cfg(feature = "network")]
use common::repository::remote::Remote;

/// Prints command line usage.
fn print_usage(bin: &str) {
eprintln!(
Expand Down
8 changes: 4 additions & 4 deletions client/src/remove.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! TODO doc
use common::anyhow::Result;
use common::anyhow::{anyhow, bail};
use common::package;
use common::Environment;
use common::{
anyhow::{anyhow, bail, Result},
package, Environment,
};

// TODO ask for confirm before remove

Expand Down
6 changes: 2 additions & 4 deletions client/src/update.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
//! This module handles packages list updating.
use anyhow::anyhow;
use anyhow::Result;
use common::repository::remote::Remote;
use common::Environment;
use anyhow::{anyhow, Result};
use common::{repository::remote::Remote, Environment};

/// Updates the packages list.
pub async fn update(env: &mut Environment) -> Result<()> {
Expand Down
14 changes: 7 additions & 7 deletions common/src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
use anyhow::Result;
use bytes::Bytes;
use futures_util::stream::Stream;
use futures_util::stream::StreamExt;
use std::fs::File;
use std::fs::OpenOptions;
use std::io::Write;
use std::path::Path;
use std::pin::Pin;
use futures_util::stream::{Stream, StreamExt};
use std::{
fs::{File, OpenOptions},
io::Write,
path::Path,
pin::Pin,
};

/// A download task, running until the file has been downloaded entirely.
pub struct DownloadTask {
Expand Down
17 changes: 8 additions & 9 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ pub use anyhow;
pub mod download;

use anyhow::Result;
use package::InstalledPackage;
use package::Package;
use package::{InstalledPackage, Package};
use repository::Repository;
use std::collections::HashMap;
use std::error::Error;
use std::fs;
use std::io;
use std::io::ErrorKind;
use std::path::Path;
use std::path::PathBuf;
use std::{
collections::HashMap,
error::Error,
fs, io,
io::ErrorKind,
path::{Path, PathBuf},
};

/// The directory containing cached packages.
const LOCKFILE_PATH: &str = "/usr/lib/blimp/.lock";
Expand Down
8 changes: 3 additions & 5 deletions common/src/lockfile.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
//! The lock file allows to prevent several instances of the package manager from running at the
//! same time.
use std::fs;
use std::fs::OpenOptions;
use std::io;
use std::path::Path;
use std::{fs, fs::OpenOptions, io, path::Path};

/// Creates the lock file if not present.
///
Expand All @@ -15,7 +12,8 @@ pub fn lock(path: &Path) -> io::Result<bool> {
if let Some(parent) = path.parent() {
fs::create_dir_all(parent)?;
}
// Trying to create the file and failing if it already exists, preventing TOCTOU race conditions
// Trying to create the file and failing if it already exists, preventing TOCTOU race
// conditions
let acquired = OpenOptions::new()
.write(true)
.create_new(true)
Expand Down
26 changes: 13 additions & 13 deletions common/src/package.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
//! A package is a software that can be installed using the package manager.
//! Packages are usualy downloaded from a remote host.
use crate::repository::Repository;
use crate::version::Version;
use crate::version::VersionConstraint;
use serde::Deserialize;
use serde::Serialize;
use std::collections::HashMap;
use std::fmt;
use std::fmt::Display;
use std::fmt::Formatter;
use std::fs;
use std::io;
use std::io::ErrorKind;
use std::path::PathBuf;
use crate::{
repository::Repository,
version::{Version, VersionConstraint},
};
use serde::{Deserialize, Serialize};
use std::{
collections::HashMap,
fmt,
fmt::{Display, Formatter},
fs, io,
io::ErrorKind,
path::PathBuf,
};

/// The directory storing packages' descriptions on the serverside.
pub const SERVER_PACKAGES_DESC_DIR: &str = "public_desc";
Expand Down
12 changes: 5 additions & 7 deletions common/src/repository/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
#[cfg(feature = "network")]
pub mod remote;

use crate::package::Package;
use crate::version::Version;
use crate::version::VersionConstraint;
use std::fs;
use std::io;
use std::path::PathBuf;

use crate::{
package::Package,
version::{Version, VersionConstraint},
};
#[cfg(feature = "network")]
use remote::Remote;
use std::{fs, io, path::PathBuf};

/// Structure representing a local repository.
pub struct Repository {
Expand Down
20 changes: 7 additions & 13 deletions common/src/repository/remote.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
//! A remote is a remote host from which packages can be downloaded.
use crate::download::DownloadTask;
use crate::package::Package;
use crate::repository::Repository;
use crate::Environment;
use anyhow::anyhow;
use anyhow::Result;
use std::fs::File;
use std::fs::OpenOptions;
use std::io;
use std::io::BufRead;
use std::io::BufReader;
use std::io::BufWriter;
use std::io::Write;
use crate::{download::DownloadTask, package::Package, repository::Repository, Environment};
use anyhow::{anyhow, Result};
use std::{
fs::{File, OpenOptions},
io,
io::{BufRead, BufReader, BufWriter, Write},
};

// TODO Use https

Expand Down
24 changes: 10 additions & 14 deletions common/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@
use bzip2::read::BzDecoder;
use flate2::read::GzDecoder;
use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};
use serde::Deserialize;
use serde::Serialize;
use std::fs;
use std::fs::File;
use std::fs::OpenOptions;
use std::io;
use std::io::BufReader;
use std::io::BufWriter;
use std::io::Read;
use std::os::unix;
use std::path::Path;
use std::path::PathBuf;
use rand::{distributions::Alphanumeric, thread_rng, Rng};
use serde::{Deserialize, Serialize};
use std::{
fs,
fs::{File, OpenOptions},
io,
io::{BufReader, BufWriter, Read},
os::unix,
path::{Path, PathBuf},
};
use tar::Archive;
use xz2::read::XzDecoder;

Expand Down
18 changes: 7 additions & 11 deletions common/src/version.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
//! The version structure represents the version of a package.
use serde::de::Error;
use serde::Deserialize;
use serde::Deserializer;
use serde::Serialize;
use serde::Serializer;
use std::cmp::min;
use std::cmp::Ordering;
use std::fmt;
use std::fmt::Display;
use std::fmt::Formatter;
use std::num::ParseIntError;
use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer};
use std::{
cmp::{min, Ordering},
fmt,
fmt::{Display, Formatter},
num::ParseIntError,
};

/// Structure representing a version.
#[derive(Clone, Eq, Hash, PartialEq)]
Expand Down
Loading

0 comments on commit f6e8bf3

Please sign in to comment.