Coverage Report

Created: 2026-07-16 06:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/filetime-0.2.29/src/unix/mod.rs
Line
Count
Source
1
use crate::FileTime;
2
use libc::{time_t, timespec, UTIME_OMIT};
3
use std::fs;
4
use std::io;
5
use std::os::unix::prelude::*;
6
use std::path::Path;
7
8
cfg_if::cfg_if! {
9
    if #[cfg(target_os = "linux")] {
10
        mod utimes;
11
        mod linux;
12
        pub use self::linux::*;
13
    } else if #[cfg(target_os = "android")] {
14
        mod android;
15
        pub use self::android::*;
16
    } else if #[cfg(target_os = "macos")] {
17
        mod utimes;
18
        mod macos;
19
        pub use self::macos::*;
20
    } else if #[cfg(any(target_os = "aix",
21
                        target_os = "nto",
22
                        target_os = "solaris",
23
                        target_os = "illumos",
24
                        target_os = "emscripten",
25
                        target_os = "freebsd",
26
                        target_os = "netbsd",
27
                        target_os = "openbsd",
28
                        target_os = "haiku"))] {
29
        mod utimensat;
30
        pub use self::utimensat::*;
31
    } else {
32
        mod utimes;
33
        pub use self::utimes::*;
34
    }
35
}
36
37
#[allow(dead_code)]
38
2.37k
fn to_timespec(ft: &Option<FileTime>) -> timespec {
39
2.37k
    let mut ts: timespec = unsafe { std::mem::zeroed() };
40
2.37k
    if let &Some(ft) = ft {
41
2.37k
        ts.tv_sec = ft.seconds() as time_t;
42
2.37k
        ts.tv_nsec = ft.nanoseconds() as _;
43
2.37k
    } else {
44
0
        ts.tv_sec = 0;
45
0
        ts.tv_nsec = UTIME_OMIT as _;
46
0
    }
47
48
2.37k
    ts
49
2.37k
}
50
51
0
pub fn from_last_modification_time(meta: &fs::Metadata) -> FileTime {
52
0
    FileTime {
53
0
        seconds: meta.mtime(),
54
0
        nanos: meta.mtime_nsec() as u32,
55
0
    }
56
0
}
57
58
0
pub fn from_last_access_time(meta: &fs::Metadata) -> FileTime {
59
0
    FileTime {
60
0
        seconds: meta.atime(),
61
0
        nanos: meta.atime_nsec() as u32,
62
0
    }
63
0
}
64
65
0
pub fn from_creation_time(meta: &fs::Metadata) -> Option<FileTime> {
66
0
    meta.created().map(|i| i.into()).ok()
67
0
}
68
69
0
pub fn open(path: &Path) -> io::Result<fs::File> {
70
    // Try a read-only open, but if that fails try a write-only open, and if
71
    // that fails then give up.
72
0
    fs::File::open(path).or_else(|_| fs::OpenOptions::new().write(true).open(path))
73
0
}