Skip to content

Commit

Permalink
Run clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
matsimitsu committed Jul 13, 2024
1 parent 96f2c0c commit 87e242f
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 44 deletions.
4 changes: 2 additions & 2 deletions bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use camino::Utf8PathBuf;
use chrono::Utc;
use clap::{Parser, Subcommand};
use config::manager::ManagerConfig;
use log;

use manager::Manager;
use std::env;
use std::process::ExitCode;
Expand Down Expand Up @@ -107,7 +107,7 @@ fn manage(args: ManageArgs) -> Result<()> {
setup_logger(args.log_level.unwrap_or(log::LevelFilter::Info)).expect("Could not setup logger");

let config =
ManagerConfig::from_file(&args.config.clone().into()).expect("Could not load config");
ManagerConfig::from_file(&args.config.clone()).expect("Could not load config");
let mut manager = Manager::new(config);

match args.debug_role {
Expand Down
4 changes: 2 additions & 2 deletions builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Builder {
let own_path: Utf8PathBuf = env::current_exe()?.try_into()?;

Ok(Self {
own_path: own_path.into(),
own_path,
source_path: [&current_dir, source_path].iter().collect(),
output_path: [&current_dir, output_path].iter().collect(),
size_gb: size_gb.unwrap_or(DEFAULT_IMAGE_SIZE_GB),
Expand Down Expand Up @@ -100,7 +100,7 @@ impl Builder {
&self.own_path,
self.mount_path.join("sbin/actions-init")
);
fs::copy_sparse(&self.own_path, &self.mount_path.join("sbin/actions-init"))?;
fs::copy_sparse(&self.own_path, self.mount_path.join("sbin/actions-init"))?;

debug!("Unmounting the image from: '{}'", &self.mount_path);
// Unmount the image
Expand Down
2 changes: 1 addition & 1 deletion config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use thiserror::*;
use toml;


pub mod firecracker;
pub mod manager;
Expand Down
6 changes: 3 additions & 3 deletions github/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use reqwest;

use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -27,7 +27,7 @@ impl GitHub {
pub fn registration_token(&self) -> Result<String> {
let registration_token_result = self
.client
.post(&format!(
.post(format!(
"https://api.github.com/orgs/{}/actions/runners/registration-token",
self.org
))
Expand All @@ -42,7 +42,7 @@ impl GitHub {

pub fn remove_runner(&self, runner_name: &str) -> Result<()> {
self.client
.post(&format!(
.post(format!(
"https://api.github.com/orgs/{}/actions/runners/remove-token",
self.org
))
Expand Down
6 changes: 3 additions & 3 deletions initialiser/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ pub fn setup_cache(cache_str: &str) -> Result<(), CacheError> {
mount::mount_ext4("/dev/vdb", CACHE_PATH)?;
set_permissions(CACHE_PATH, Permissions::from_mode(0o777))?;

let cache_links = cache_str.split(",");
let cache_links = cache_str.split(',');
for cache_link in cache_links {
let cache_link = cache_link.trim();
let cache_parts: Vec<&str> = cache_link.split(":").collect();
let cache_parts: Vec<&str> = cache_link.split(':').collect();
if cache_parts.len() != 2 {
return Err(CacheError::Io(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
Expand All @@ -33,7 +33,7 @@ pub fn setup_cache(cache_str: &str) -> Result<(), CacheError> {
let cache_path = cache_parts[1];

fs::mkdir_p(&cache_root)?;
symlink(&cache_root, &cache_path)?;
symlink(&cache_root, cache_path)?;
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion initialiser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl Initialiser {
Ok(github_runner_labels),
) => {
debug!("Copy self to actions-runner");
copy(&self.own_path, &Utf8PathBuf::from("/sbin/actions-run"))?;
copy(&self.own_path, Utf8PathBuf::from("/sbin/actions-run"))?;

debug!("Set runner init script");
service::setup_service(
Expand Down
6 changes: 3 additions & 3 deletions initialiser/src/network.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use config::{NETWORK_MAGIC_MAC_START, NETWORK_MASK_SHORT};
use serde::Deserialize;
use serde_json;

use std::{fs::write, net::Ipv4Addr, process::Command};
use thiserror::Error;
use util::{exec, network::mac_to_ip};
Expand Down Expand Up @@ -53,7 +53,7 @@ pub fn get_magic_address() -> Result<NetworkAddress, NetworkError> {
return Ok(interface);
}
}
Err(NetworkError::NoInterfaceFound.into())
Err(NetworkError::NoInterfaceFound)
}

pub fn setup_network() -> Result<Option<NetworkInterface>, NetworkError> {
Expand All @@ -72,7 +72,7 @@ pub fn setup_network() -> Result<Option<NetworkInterface>, NetworkError> {
exec(Command::new("ip").args([
"addr",
"add",
&format!("{}/{}", own_ip.to_string(), NETWORK_MASK_SHORT),
&format!("{}/{}", own_ip, NETWORK_MASK_SHORT),
"dev",
&magic_address.ifname,
]))?;
Expand Down
4 changes: 2 additions & 2 deletions manager/src/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl Disk {
}

pub fn path_with_filename(&self) -> Utf8PathBuf {
self.path.join(&self.filename())
self.path.join(self.filename())
}

pub fn setup(&self) -> Result<(), std::io::Error> {
Expand All @@ -46,7 +46,7 @@ impl Disk {

pub fn setup_ext4(&self) -> Result<(), std::io::Error> {
fs::dd(self.path_with_filename(), self.size_in_megabytes())?;
fs::mkfs_ext4(&self.path_with_filename())?;
fs::mkfs_ext4(self.path_with_filename())?;
Ok(())
}
}
45 changes: 22 additions & 23 deletions manager/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Instance {
role: &Role,
idx: u8,
) -> Self {
let instance_dir: Utf8PathBuf = work_dir.join(&role.slug()).join(format!("{}", idx));
let instance_dir: Utf8PathBuf = work_dir.join(role.slug()).join(format!("{}", idx));
let cache = Disk::new(&instance_dir, "cache", role.cache_size, DiskFormat::Ext4);

Self {
Expand Down Expand Up @@ -157,29 +157,28 @@ impl Instance {
boot_args: self.boot_args()?,
};

let mut drives = Vec::new();
drives.push(Drive {
drive_id: "rootfs".to_string(),
path_on_host: self.work_dir.join("rootfs.ext4"),
is_root_device: true,
is_read_only: false,
cache_type: None,
});

drives.push(Drive {
drive_id: "cache".to_string(),
path_on_host: self.cache.path_with_filename(),
is_root_device: false,
is_read_only: false,
cache_type: None,
});

let mut network_interfaces = Vec::new();
network_interfaces.push(NetworkInterface {
let drives = vec![
Drive {
drive_id: "rootfs".to_string(),
path_on_host: self.work_dir.join("rootfs.ext4"),
is_root_device: true,
is_read_only: false,
cache_type: None,
},
Drive {
drive_id: "cache".to_string(),
path_on_host: self.cache.path_with_filename(),
is_root_device: false,
is_read_only: false,
cache_type: None,
},
];

let network_interfaces = vec![NetworkInterface {
iface_id: "eth0".to_string(),
guest_mac: self.network_allocation.guest_mac.clone(),
host_dev_name: self.network_allocation.tap_name.clone(),
});
}];

let machine_config = MachineConfig {
vcpu_count: self.cpus,
Expand All @@ -201,8 +200,8 @@ impl Instance {
self.rootfs_image,
self.work_dir.join("rootfs.ext4"),
);
let _ = rm_rf(&self.work_dir.join("rootfs.ext4"));
copy_sparse(&self.rootfs_image, &self.work_dir.join("rootfs.ext4"))?;
let _ = rm_rf(self.work_dir.join("rootfs.ext4"));
copy_sparse(&self.rootfs_image, self.work_dir.join("rootfs.ext4"))?;

debug!(
"{} Generate config: '{}'",
Expand Down
4 changes: 2 additions & 2 deletions manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct Manager {

impl Manager {
pub fn new(config: ManagerConfig) -> Self {
let mut signals = Signals::new(&[SIGINT]).unwrap();
let mut signals = Signals::new([SIGINT]).unwrap();
let shutdown = Arc::new(AtomicBool::new(false));
let cloned_shutdown = shutdown.clone();

Expand Down Expand Up @@ -59,7 +59,7 @@ impl Manager {
network_allocation,
github.clone(),
&self.config.run_path,
&role,
role,
idx,
);
instance.setup()?;
Expand Down
6 changes: 6 additions & 0 deletions runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ use util::exec;

pub struct Runner {}

impl Default for Runner {
fn default() -> Self {
Self::new()
}
}

impl Runner {
pub fn new() -> Self {
Runner {}
Expand Down
2 changes: 1 addition & 1 deletion util/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use cfg_if::cfg_if;
#[allow(unused)]
use lazy_static::lazy_static;
use log;

#[allow(unused)]
use std::sync::atomic::{AtomicBool, Ordering};
#[allow(unused)]
Expand Down
2 changes: 1 addition & 1 deletion util/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn ip_to_mac(ip: &Ipv4Addr) -> String {
pub fn mac_to_ip(mac: &str) -> Result<Ipv4Addr, MacToIpError> {
let octets = mac
.replace("06:00:", "")
.split(":")
.split(':')
.map(|octet| u8::from_str_radix(octet, 16))
.collect::<Result<Vec<u8>, ParseIntError>>()
.map_err(|_| MacToIpError::NoIpInMac(mac.to_string()))?;
Expand Down

0 comments on commit 87e242f

Please sign in to comment.