Skip to content

Commit 9e1db72

Browse files
committed
Add basic touch command implementation
1 parent 2bb0b70 commit 9e1db72

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

docs/touch.txt

Whitespace-only changes.

src/bin/touch.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use std::io::stdout;
2+
3+
use puppyutils::{Result, cli};
4+
use xenia::{AtFlags, ClockId, Timestamps, clock_gettime, stdio::cwd, utimensat};
5+
6+
pub fn main() -> Result {
7+
let mut stdout = stdout();
8+
let mut files = Vec::new();
9+
10+
cli! {
11+
"touch", stdout, #error
12+
Value(value) => {
13+
files.push(value.into_owned());
14+
}
15+
};
16+
17+
let now = clock_gettime(ClockId::Realtime)?;
18+
19+
let timestamps = Timestamps {
20+
last_access: now,
21+
last_modification: now,
22+
};
23+
24+
for file in files {
25+
utimensat(cwd(), file, &timestamps, AtFlags::empty())?
26+
}
27+
28+
Ok(())
29+
}

src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub mod bin {
99
pub mod ls;
1010
pub mod mkdir;
1111
pub mod pwd;
12+
pub mod touch;
1213
pub mod r#true;
1314
pub mod tty;
1415
pub mod uname;
@@ -33,6 +34,7 @@ fn main() -> Result {
3334
b"ls" => bin::ls::main(),
3435
b"mkdir" => bin::mkdir::main(),
3536
b"pwd" => bin::pwd::main(),
37+
b"touch" => bin::touch::main(),
3638
b"true" => bin::r#true::main(),
3739
b"tty" => bin::tty::main(),
3840
b"uname" => bin::uname::main(),

0 commit comments

Comments
 (0)