Begins work on dd

- Prototype code.
- Adds project boilerplate for integration with coreutils framework.
This commit is contained in:
ty 2021-03-16 14:32:55 -07:00
parent 4574b2b58d
commit af6bf3a224
7 changed files with 168 additions and 0 deletions

11
Cargo.lock generated
View file

@ -1,3 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "advapi32-sys"
version = "0.2.0"
@ -219,6 +221,7 @@ dependencies = [
"uu_csplit 0.0.4",
"uu_cut 0.0.4",
"uu_date 0.0.4",
"uu_dd 0.0.4",
"uu_df 0.0.4",
"uu_dircolors 0.0.4",
"uu_dirname 0.0.4",
@ -1495,6 +1498,14 @@ dependencies = [
"uucore_procs 0.0.5",
]
[[package]]
name = "uu_dd"
version = "0.0.4"
dependencies = [
"uucore 0.0.7",
"uucore_procs 0.0.5",
]
[[package]]
name = "uu_df"
version = "0.0.4"

View file

@ -150,6 +150,7 @@ feat_require_unix = [
"chown",
"chroot",
"du",
"dd",
"groups",
"hostid",
"id",
@ -249,6 +250,7 @@ df = { optional=true, version="0.0.4", package="uu_df", path="src/uu/df" }
dircolors= { optional=true, version="0.0.4", package="uu_dircolors", path="src/uu/dircolors" }
dirname = { optional=true, version="0.0.4", package="uu_dirname", path="src/uu/dirname" }
du = { optional=true, version="0.0.4", package="uu_du", path="src/uu/du" }
dd = { optional=true, version="0.0.4", package="uu_dd", path="src/uu/dd" }
echo = { optional=true, version="0.0.4", package="uu_echo", path="src/uu/echo" }
env = { optional=true, version="0.0.4", package="uu_env", path="src/uu/env" }
expand = { optional=true, version="0.0.4", package="uu_expand", path="src/uu/expand" }

23
src/uu/dd/Cargo.toml Normal file
View file

@ -0,0 +1,23 @@
[package]
name = "uu_dd"
version = "0.0.4"
authors = ["uutils developers"]
license = "MIT"
description = "dd ~ (uutils) copy and convert files"
homepage = "https://github.com/uutils/coreutils"
repository = "https://github.com/uutils/coreutils/tree/master/src/uu/dd"
keywords = ["coreutils", "uutils", "cross-platform", "cli", "utility"]
categories = ["command-line-utilities"]
edition = "2018"
[lib]
path = "src/dd.rs"
[dependencies]
uucore = { version=">=0.0.7", package="uucore", path="../../uucore" }
uucore_procs = { version=">=0.0.5", package="uucore_procs", path="../../uucore_procs" }
[[bin]]
name = "dd"
path = "src/main.rs"

15
src/uu/dd/Makefile Normal file
View file

@ -0,0 +1,15 @@
##
# Test runner
#
# @file
# @version 0.1
all: int unit
int:
cargo test --features "dd" --no-default-features --manifest-path "../../../Cargo.toml"
unit:
cargo test --manifest-path "./Cargo.toml"
# end

109
src/uu/dd/src/dd.rs Normal file
View file

@ -0,0 +1,109 @@
// This file is part of the uutils coreutils package.
//
// (c) Tyler Steele <tyler.steele@protonmail.com>
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
// spell-checker:ignore (T0DO)
#[macro_use]
extern crate uucore;
use std::error::Error;
use std::io;
use std::sync::mpsc;
use std::thread;
const NAME: &str = "dd";
const SUMMARY: &str = "Copies, and optionally converts, file system resources.";
const LONG_HELP: &str = "
TODO: This is where the long help string for dd goes!
";
struct Input
{
src: Box<dyn io::Read>,
}
impl Input
{
fn run(&self, tx: mpsc::SyncSender<Vec<u8>>) -> Result<(), Box<dyn Error>>
{
let buff = vec![0; 128];
let msg = self.src.read(&buff)?;
println!("Sender sending:\t\t{:?}", &msg);
tx.send(msg)?;
Ok(())
}
}
struct Output
{
dst: Box<dyn io::Write>,
}
impl Output
{
fn run(&self, rx: mpsc::Receiver<Vec<u8>>) -> Result<(), Box<dyn Error>>
{
let data = rx.recv()?;
println!("Receiver received:\t{:?}", data);
Ok(())
}
}
fn dd(i: Input, o: Output) -> ()
{
let (tx, rx) = mpsc::sync_channel(0); // each send will block until the recv'r is ready for it
thread::spawn(move || {
i.run(tx);
});
thread::spawn(move || {
o.run(rx);
});
loop{};
}
pub fn uumain(args: impl uucore::Args) -> i32
{
// TODO: parse args
-1
}
#[cfg(test)]
mod test_dd_internal {
#[allow(unused_imports)]
use super::*;
#[test]
fn hello_world_test()
{
let (src, dst) = mpsc::channel();
let data = vec![0xFF; 128];
for c in data {
src.send(c);
}
let i = Input {
src: Box::new(src),
};
let o = Output {
dst: Box::new(dst),
};
dd(i,o);
assert_eq!(data, dst);
}
}

1
src/uu/dd/src/main.rs Normal file
View file

@ -0,0 +1 @@
uucore_procs::main!(uu_dd); // spell-checker:ignore procs uucore

7
tests/by-util/test_dd.rs Normal file
View file

@ -0,0 +1,7 @@
use crate::common::util::*;
#[test]
fn fail_from_test_dd()
{
panic!()
}