Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
fixed clippy warning
Browse files Browse the repository at this point in the history
  • Loading branch information
guni1192 committed Dec 24, 2018
1 parent 5f68bd2 commit 6514bea
Show file tree
Hide file tree
Showing 7 changed files with 247 additions and 30 deletions.
2 changes: 2 additions & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[alias]
arch01 = "run -- run -n arch01"
224 changes: 224 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ edition = "2018"
[dependencies]
nix = "0.11.0"
getopts = "0.2"
dirs = "1.0"
2 changes: 1 addition & 1 deletion src/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::process::Command;
pub fn pacstrap(container_path: &str) {
let mut pacstrap = Command::new("pacstrap")
.arg("-i")
.arg(format!("{}", container_path))
.arg(container_path.to_string())
.arg("base")
.arg("base-devel")
.arg("dnsutils")
Expand Down
6 changes: 4 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use std::process;
use std::process::exit;

use nix::sched::{unshare, CloneFlags};
use nix::unistd::{chdir, chroot, getpgid, getuid, Pid, Uid};
use nix::unistd::{chdir, chroot, getpgid, getuid, Pid};

use dirs::home_dir;

use super::bootstrap::pacstrap;
use super::container;
Expand All @@ -20,7 +22,7 @@ pub fn run(args: &[String]) {

let ace_container_path_env = "ACE_CONTAINER_PATH";
// TODO: settting.rsからの読み込みに変更
let home_dir = env::home_dir().expect("Cannot get $HOME");
let home_dir = home_dir().expect("Cannot get $HOME");
let ace_path = format!("{}/{}", home_dir.display(), "ace-containers");
env::set_var(ace_container_path_env, ace_path);

Expand Down
8 changes: 4 additions & 4 deletions src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ impl Container {

Container {
name: name.clone(),
path: path,
command: command,
uid: uid,
pgid: pgid,
path,
command,
uid,
pgid,
network: initialize_network(name),
}
}
Expand Down
34 changes: 11 additions & 23 deletions src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,9 @@ impl Bridge {
}

pub fn existed(&self) -> bool {
let addrs = nix::ifaddrs::getifaddrs().unwrap();
let ifname = addrs
.into_iter()
.filter(|ifaddr| ifaddr.interface_name == self.name)
.next();
match ifname {
Some(_) => true,
None => false,
}
let mut addrs = nix::ifaddrs::getifaddrs().unwrap();
let ifname = addrs.find(|ifaddr| ifaddr.interface_name == self.name);
ifname.is_some()
}
}

Expand All @@ -69,11 +63,11 @@ impl Network {
container_ip: IpAddr,
) -> Network {
Network {
namespace: namespace,
bridge: bridge,
veth_host: veth_host,
veth_guest: veth_guest,
container_ip: container_ip,
namespace,
bridge,
veth_host,
veth_guest,
container_ip,
pid: process::id(),
}
}
Expand Down Expand Up @@ -129,15 +123,9 @@ impl Network {
}

pub fn existed_veth(&self) -> bool {
let addrs = nix::ifaddrs::getifaddrs().unwrap();
let ifname = addrs
.into_iter()
.filter(|ifaddr| ifaddr.interface_name == self.veth_host)
.next();
match ifname {
Some(_) => true,
None => false,
}
let mut addrs = nix::ifaddrs::getifaddrs().unwrap();
let ifname = addrs.find(|ifaddr| ifaddr.interface_name == self.veth_host);
ifname.is_some()
}

pub fn add_container_network(&self) -> Result<(), ()> {
Expand Down

0 comments on commit 6514bea

Please sign in to comment.