12 releases

0.3.3 Oct 9, 2024
0.3.2 Oct 9, 2024
0.3.1 Jul 10, 2020
0.3.0 May 21, 2020
0.0.1 Jul 28, 2015

#341 in Filesystem

Download history 2469/week @ 2024-08-26 2445/week @ 2024-09-02 2418/week @ 2024-09-09 1942/week @ 2024-09-16 2083/week @ 2024-09-23 1966/week @ 2024-09-30 2509/week @ 2024-10-07 1951/week @ 2024-10-14 1963/week @ 2024-10-21 1411/week @ 2024-10-28 1310/week @ 2024-11-04 1627/week @ 2024-11-11 1925/week @ 2024-11-18 1468/week @ 2024-11-25 1191/week @ 2024-12-02 1488/week @ 2024-12-09

6,262 downloads per month
Used in 4 crates (2 directly)

Apache-2.0 OR MIT

12KB
129 lines

utime - Deprecated version

This crate was originally created to provide a missing utime function for Rust, allowing users to set the atime/mtime of a file, as the Rust standard library did not offer a stable method for this functionality.

As of Rust 1.75.0, the standard library now includes File::set_times, which provides a stable and native way to update a file’s last modification and access time.

Recommendation

If you are using Rust 1.75.0 or later, it is recommended to use the native File::set_times function instead of this crate.

use std::fs::{File, FileTimes};
use std::io::Result;
use std::time::SystemTime;

fn main() -> Result<()> {
    let times = FileTimes::new()
        .set_accessed(SystemTime::now())
        .set_modified(SystemTime::UNIX_EPOCH);
    File::create("target/testdummy")?.set_times(times)?;
    Ok(())
}

For Rust <1.75.0 users

For projects using older Rust versions, you may still find this library useful. See documentation for the further details.

[dependencies]
utime = "0.3"
use std::fs::File;
use std::io::Result;
use utime::*;

fn main() -> Result<()> {
    File::create("target/testdummy")?;
    set_file_times("target/testdummy", 1000000, 1000000000)?;

    let (accessed, modified) = get_file_times("target/testdummy")?;
    assert_eq!(accessed, 1000000);
    assert_eq!(modified, 1000000000);
    Ok(())
}

 


utime is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0). See COPYRIGHT for details.

Dependencies

~220KB