Coverage Report

Created: 2026-08-05 07:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/jiff-0.2.35/src/util/fs.rs
Line
Count
Source
1
use std::{fs::File, path::Path};
2
3
use crate::Timestamp;
4
5
/// Returns the last modified time for the given file path as a Jiff timestamp.
6
///
7
/// If there was a problem accessing the last modified time or if it could not
8
/// fit in a Jiff timestamp, then a warning message is logged and `None` is
9
/// returned.
10
0
pub(crate) fn last_modified_from_path(path: &Path) -> Option<Timestamp> {
11
0
    let file = match File::open(path) {
12
0
        Ok(file) => file,
13
0
        Err(_err) => {
14
            warn!(
15
                "failed to open file to get last modified time {}: {_err}",
16
                path.display(),
17
            );
18
0
            return None;
19
        }
20
    };
21
0
    last_modified_from_file(path, &file)
22
0
}
23
24
/// Returns the last modified time for the given file as a Jiff timestamp.
25
///
26
/// If there was a problem accessing the last modified time or if it could not
27
/// fit in a Jiff timestamp, then a warning message is logged and `None` is
28
/// returned.
29
///
30
/// The path given should be the path to the given file. It is used for
31
/// diagnostic purposes.
32
0
pub(crate) fn last_modified_from_file(
33
0
    _path: &Path,
34
0
    file: &File,
35
0
) -> Option<Timestamp> {
36
0
    let md = match file.metadata() {
37
0
        Ok(md) => md,
38
0
        Err(_err) => {
39
            warn!(
40
                "failed to get metadata (for last modified time) \
41
                 for {}: {_err}",
42
                _path.display(),
43
            );
44
0
            return None;
45
        }
46
    };
47
0
    let systime = match md.modified() {
48
0
        Ok(systime) => systime,
49
0
        Err(_err) => {
50
            warn!(
51
                "failed to get last modified time for {}: {_err}",
52
                _path.display()
53
            );
54
0
            return None;
55
        }
56
    };
57
0
    let timestamp = match Timestamp::try_from(systime) {
58
0
        Ok(timestamp) => timestamp,
59
0
        Err(_err) => {
60
            warn!(
61
                "system time {systime:?} out of bounds \
62
                 for Jiff timestamp for last modified time \
63
                 from {}: {_err}",
64
                _path.display(),
65
            );
66
0
            return None;
67
        }
68
    };
69
0
    Some(timestamp)
70
0
}