refactor: fix warnings
This commit is contained in:
parent
6da1dbecc7
commit
440c89efaf
65
Cargo.lock
generated
65
Cargo.lock
generated
@ -113,43 +113,6 @@ dependencies = [
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-core"
|
||||
version = "0.3.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c"
|
||||
|
||||
[[package]]
|
||||
name = "futures-macro"
|
||||
version = "0.3.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-task"
|
||||
version = "0.3.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2"
|
||||
|
||||
[[package]]
|
||||
name = "futures-util"
|
||||
version = "0.3.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-macro",
|
||||
"futures-task",
|
||||
"pin-project-lite",
|
||||
"pin-utils",
|
||||
"slab",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.4.1"
|
||||
@ -289,18 +252,6 @@ dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pin-project-lite"
|
||||
version = "0.2.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58"
|
||||
|
||||
[[package]]
|
||||
name = "pin-utils"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
||||
|
||||
[[package]]
|
||||
name = "powerfmt"
|
||||
version = "0.2.0"
|
||||
@ -411,15 +362,6 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
version = "0.4.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.11.2"
|
||||
@ -621,13 +563,6 @@ version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
|
||||
|
||||
[[package]]
|
||||
name = "yasync"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"futures-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "yggdrasil-abi"
|
||||
version = "0.1.0"
|
||||
|
10
build.sh
10
build.sh
@ -53,6 +53,10 @@ pack_initrd() {
|
||||
cp ${build_dir}/mount ${root_dir}/sbin/
|
||||
cp ${build_dir}/login ${root_dir}/sbin/
|
||||
cp ${build_dir}/ls ${root_dir}/bin/
|
||||
cp ${build_dir}/mkdir ${root_dir}/bin/
|
||||
cp ${build_dir}/touch ${root_dir}/bin/
|
||||
cp ${build_dir}/rm ${root_dir}/bin/
|
||||
cp ${build_dir}/cat ${root_dir}/bin/
|
||||
cp ${build_dir}/hexd ${root_dir}/bin/
|
||||
cp ${build_dir}/colors ${root_dir}/bin/
|
||||
|
||||
@ -64,6 +68,8 @@ pack_initrd() {
|
||||
cd "${root_dir}"
|
||||
mkdir -p dev
|
||||
touch dev/.do_not_remove
|
||||
mkdir -p sys
|
||||
touch sys/.do_not_remove
|
||||
|
||||
tar cf ../initrd.tar `find . -type f -printf "%P\n"`
|
||||
cd -
|
||||
@ -83,6 +89,10 @@ case "$1" in
|
||||
pstatus "Creating initrd.tar"
|
||||
pack_initrd
|
||||
;;
|
||||
# clippy ignored for now
|
||||
check|clippy)
|
||||
cargo +ygg-stage1 check ${USER_CARGO_OPTS}
|
||||
;;
|
||||
**)
|
||||
;;
|
||||
esac
|
||||
|
@ -1 +1,2 @@
|
||||
/sbin/mount -t devfs /dev
|
||||
/sbin/mount -t sysfs /sys
|
||||
|
@ -1,4 +1,4 @@
|
||||
#![feature(let_chains, rustc_private, async_fn_in_trait)]
|
||||
#![feature(let_chains, rustc_private)]
|
||||
#![cfg_attr(target_os = "yggdrasil", feature(yggdrasil_raw_fd, yggdrasil_os))]
|
||||
|
||||
use std::{env, fmt::Write, path::Path};
|
||||
@ -6,7 +6,7 @@ use std::{env, fmt::Write, path::Path};
|
||||
use buffer::{Buffer, Mode, SetMode};
|
||||
use config::Config;
|
||||
use error::Error;
|
||||
use keymap::{PrefixNode, KeySeq, Key};
|
||||
use keymap::{Key, KeySeq, PrefixNode};
|
||||
use term::{Clear, Color, Term};
|
||||
|
||||
pub mod buffer;
|
||||
@ -286,7 +286,9 @@ impl State {
|
||||
self.buffer.set_mode(&self.config, SetMode::Normal);
|
||||
Ok(())
|
||||
}
|
||||
Key::Char(key) if !key.is_ascii() || key == ' ' || key == '\t' || key.is_ascii_graphic() => {
|
||||
Key::Char(key)
|
||||
if !key.is_ascii() || key == ' ' || key == '\t' || key.is_ascii_graphic() =>
|
||||
{
|
||||
self.buffer.insert(&self.config, key);
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1,10 +1,9 @@
|
||||
use std::{io::{Read, Stdin}, future::{Future, self}};
|
||||
use std::io::{Read, Stdin};
|
||||
|
||||
use crate::error::InputError;
|
||||
|
||||
pub trait ReadChar {
|
||||
fn read_char(&mut self) -> Result<char, InputError>;
|
||||
async fn read_byte_delay(&mut self);
|
||||
}
|
||||
|
||||
impl ReadChar for Stdin {
|
||||
@ -24,10 +23,6 @@ impl ReadChar for Stdin {
|
||||
let s = core::str::from_utf8(&buf[..len + 1]).map_err(InputError::DecodeError)?;
|
||||
Ok(s.chars().next().unwrap())
|
||||
}
|
||||
|
||||
async fn read_byte_delay(&mut self) {
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
|
||||
const fn utf8_len_prefix(l: u8) -> Option<usize> {
|
||||
|
@ -6,8 +6,8 @@ use nom::{
|
||||
character::complete::{space0, space1},
|
||||
combinator::{map, value, verify},
|
||||
multi::{many0, many1, separated_list0},
|
||||
sequence::{delimited, pair, preceded, terminated},
|
||||
IResult, Parser,
|
||||
sequence::{delimited, preceded},
|
||||
IResult,
|
||||
};
|
||||
|
||||
fn text(input: &str) -> IResult<&str, &str> {
|
||||
@ -79,10 +79,7 @@ fn subst_vars<'e, 's>(
|
||||
})(input)
|
||||
}
|
||||
|
||||
pub fn parse_line(
|
||||
env: &HashMap<String, String>,
|
||||
input: &str,
|
||||
) -> Result<Vec<String>, ()> {
|
||||
pub fn parse_line(env: &HashMap<String, String>, input: &str) -> Result<Vec<String>, ()> {
|
||||
let (_, substituted) = subst_vars(env, input).map_err(|_| ())?;
|
||||
let (rem, words) = parse_line_raw(&substituted).map_err(|_| ())?;
|
||||
if !rem.is_empty() {
|
||||
|
@ -27,6 +27,22 @@ path = "src/login.rs"
|
||||
name = "ls"
|
||||
path = "src/ls.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "mkdir"
|
||||
path = "src/mkdir.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "touch"
|
||||
path = "src/touch.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "rm"
|
||||
path = "src/rm.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "cat"
|
||||
path = "src/cat.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "hexd"
|
||||
path = "src/hexd.rs"
|
||||
|
24
sysutils/src/cat.rs
Normal file
24
sysutils/src/cat.rs
Normal file
@ -0,0 +1,24 @@
|
||||
use std::{
|
||||
env,
|
||||
fs::File,
|
||||
io::{stdout, BufReader, Read, Write},
|
||||
};
|
||||
|
||||
fn main() {
|
||||
let mut stdout = stdout();
|
||||
|
||||
for arg in env::args().skip(1) {
|
||||
let mut buf = [0; 4096];
|
||||
let mut reader = BufReader::new(File::open(arg).unwrap());
|
||||
|
||||
loop {
|
||||
let count = reader.read(&mut buf).unwrap();
|
||||
|
||||
if count == 0 {
|
||||
break;
|
||||
}
|
||||
|
||||
stdout.write_all(&buf[..count]).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
@ -5,16 +5,11 @@ use std::{
|
||||
io::{self, stdin, stdout, BufRead, Write},
|
||||
os::{
|
||||
fd::AsRawFd,
|
||||
yggdrasil::{
|
||||
io::{start_terminal_session, DeviceRequest, FdDeviceRequest},
|
||||
signal::{set_signal_handler, Signal, SignalHandler},
|
||||
},
|
||||
yggdrasil::io::{start_terminal_session, DeviceRequest, FdDeviceRequest},
|
||||
},
|
||||
process::{self, Command, ExitCode},
|
||||
};
|
||||
|
||||
fn handler(_signal: Signal) {}
|
||||
|
||||
fn login_readline<R: BufRead + AsRawFd>(
|
||||
reader: &mut R,
|
||||
buf: &mut String,
|
||||
|
@ -4,7 +4,6 @@ use std::{
|
||||
fmt,
|
||||
fs::{read_dir, FileType, Metadata},
|
||||
io,
|
||||
mem::MaybeUninit,
|
||||
path::Path,
|
||||
};
|
||||
|
||||
|
37
sysutils/src/mkdir.rs
Normal file
37
sysutils/src/mkdir.rs
Normal file
@ -0,0 +1,37 @@
|
||||
use std::{
|
||||
io,
|
||||
path::{Path, PathBuf},
|
||||
process::ExitCode,
|
||||
};
|
||||
|
||||
use clap::Parser;
|
||||
|
||||
#[derive(Parser)]
|
||||
struct Args {
|
||||
#[arg(short)]
|
||||
parents: bool,
|
||||
#[clap(required = true)]
|
||||
dirs: Vec<PathBuf>,
|
||||
}
|
||||
|
||||
fn mkdir<P: AsRef<Path>>(path: P, parents: bool) -> Result<(), io::Error> {
|
||||
if parents {
|
||||
std::fs::create_dir_all(path)
|
||||
} else {
|
||||
std::fs::create_dir(path)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> ExitCode {
|
||||
let args = Args::parse();
|
||||
let mut result = ExitCode::SUCCESS;
|
||||
|
||||
for arg in args.dirs {
|
||||
if let Err(e) = mkdir(&arg, args.parents) {
|
||||
eprintln!("{}: {}", arg.display(), e);
|
||||
result = ExitCode::FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
result
|
||||
}
|
71
sysutils/src/rm.rs
Normal file
71
sysutils/src/rm.rs
Normal file
@ -0,0 +1,71 @@
|
||||
#![feature(io_error_more)]
|
||||
use std::{io, fs, path::{Path, PathBuf}, process::ExitCode};
|
||||
|
||||
use clap::Parser;
|
||||
|
||||
#[derive(Parser)]
|
||||
struct Args {
|
||||
#[arg(short)]
|
||||
recurse: bool,
|
||||
#[clap(required = true)]
|
||||
paths: Vec<PathBuf>
|
||||
}
|
||||
|
||||
fn rm<P: AsRef<Path>>(path: P, recurse: bool) -> bool {
|
||||
let path = path.as_ref();
|
||||
println!("remove {}", path.display());
|
||||
|
||||
match fs::remove_file(path) {
|
||||
Err(e) if recurse && e.kind() == io::ErrorKind::IsADirectory => {
|
||||
let readdir = match fs::read_dir(path) {
|
||||
Ok(dir) => dir,
|
||||
Err(error) => {
|
||||
eprintln!("{}: {}", path.display(), error);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
let mut result = true;
|
||||
|
||||
for entry in readdir {
|
||||
let entry = match entry {
|
||||
Ok(entry) => entry,
|
||||
Err(error) => {
|
||||
eprintln!("{}/: {}", path.display(), error);
|
||||
result = false;
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
result &= rm(entry.path(), recurse);
|
||||
}
|
||||
|
||||
if result {
|
||||
if let Err(error) = fs::remove_dir(path) {
|
||||
eprintln!("{}: {}", path.display(), error);
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
|
||||
result
|
||||
},
|
||||
Err(e) => {
|
||||
eprintln!("{}: {}", path.display(), e);
|
||||
false
|
||||
}
|
||||
Ok(_) => true
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> ExitCode {
|
||||
let args = Args::parse();
|
||||
let mut result = ExitCode::SUCCESS;
|
||||
|
||||
for arg in args.paths {
|
||||
if !rm(arg, args.recurse) {
|
||||
result = ExitCode::FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
result
|
||||
}
|
26
sysutils/src/touch.rs
Normal file
26
sysutils/src/touch.rs
Normal file
@ -0,0 +1,26 @@
|
||||
use std::{env, fs::OpenOptions, io, path::Path, process::ExitCode};
|
||||
|
||||
fn touch<P: AsRef<Path>>(path: P) -> Result<(), io::Error> {
|
||||
OpenOptions::new().create(true).write(true).open(path)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> ExitCode {
|
||||
let mut args = env::args();
|
||||
|
||||
if args.len() < 2 {
|
||||
eprintln!("Usage: {} FILES", args.next().unwrap());
|
||||
return ExitCode::FAILURE;
|
||||
}
|
||||
|
||||
let mut result = ExitCode::SUCCESS;
|
||||
|
||||
for arg in args.skip(1) {
|
||||
if let Err(err) = touch(&arg) {
|
||||
eprintln!("{}: {}", arg, err);
|
||||
result = ExitCode::FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
result
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user