Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ version = "0.1.0"
extra = { git = "https://github.com/redox-os/libextra.git" }
termion = { git = "https://github.com/redox-os/termion.git" }
userutils = { git = "https://github.com/redox-os/userutils.git" }
filetime = { git = "https://github.com/ids1024/filetime.git", branch = "redox2" }
redox_syscall = "0.1"
walkdir = "1"
time = "0.1"
Expand Down
16 changes: 5 additions & 11 deletions src/bin/touch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
extern crate coreutils;
extern crate extra;
extern crate syscall;
extern crate filetime;

use std::env;
use std::fs::File;
use std::io::{stdout, stderr, Error, Write};
use std::io::{stdout, stderr, Write};
use std::time::{SystemTime, UNIX_EPOCH};
use std::path::Path;
use std::process::exit;
use coreutils::ArgParser;
use extra::option::OptionalExt;
use extra::io::fail;
use syscall::data::TimeSpec;
use syscall::flag::O_WRONLY;
use filetime::{set_file_times, FileTime};

const MAN_PAGE: &'static str = /* @MANSTART{touch} */ r#"
NAME
Expand Down Expand Up @@ -54,14 +54,8 @@ fn main() {
for arg in env::args().skip(1) {
if Path::new(&arg).is_file() {
let mtime = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();

let file = syscall::open(&arg, O_WRONLY).map_err(|e| Error::from_raw_os_error(e.errno)).try(&mut stderr);
let res = syscall::futimens(file, &[TimeSpec {
tv_sec: mtime.as_secs() as i64,
tv_nsec: mtime.subsec_nanos() as i32,
}]).map_err(|e| Error::from_raw_os_error(e.errno));
let _ = syscall::close(file);
res.try(&mut stderr);
let time = FileTime::from_seconds_since_1970(mtime.as_secs(), mtime.subsec_nanos());
set_file_times(&arg, time, time).try(&mut stderr);
} else {
File::create(&arg).try(&mut stderr);
}
Expand Down