mirror of
https://github.com/starship/starship.git
synced 2024-12-26 00:58:52 +01:00
chore(context): Use monotonic clock for timeout (#1802)
Have switched to use a monotonic clock for calculating the timeout when indexing the current directory for the context to avoid any issues with calculating the timeout when the systems clock might change.
This commit is contained in:
parent
95bb901b8a
commit
035e80bbd3
@ -11,7 +11,7 @@ use std::ffi::OsString;
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::string::String;
|
use std::string::String;
|
||||||
use std::time::{Duration, SystemTime};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
/// Context contains data or common methods that may be used by multiple modules.
|
/// Context contains data or common methods that may be used by multiple modules.
|
||||||
/// The data contained within Context will be relevant to this particular rendering
|
/// The data contained within Context will be relevant to this particular rendering
|
||||||
@ -223,7 +223,7 @@ impl DirContents {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn from_path_with_timeout(base: &PathBuf, timeout: Duration) -> Result<Self, std::io::Error> {
|
fn from_path_with_timeout(base: &PathBuf, timeout: Duration) -> Result<Self, std::io::Error> {
|
||||||
let start = SystemTime::now();
|
let start = Instant::now();
|
||||||
|
|
||||||
let mut folders: HashSet<PathBuf> = HashSet::new();
|
let mut folders: HashSet<PathBuf> = HashSet::new();
|
||||||
let mut files: HashSet<PathBuf> = HashSet::new();
|
let mut files: HashSet<PathBuf> = HashSet::new();
|
||||||
@ -233,8 +233,8 @@ impl DirContents {
|
|||||||
fs::read_dir(base)?
|
fs::read_dir(base)?
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.take_while(|(n, _)| {
|
.take_while(|(n, _)| {
|
||||||
n & 0xFF != 0 // only check SystemTime once every 2^8 entries
|
n & 0xFF != 0 // only check timeout once every 2^8 entries
|
||||||
|| SystemTime::now().duration_since(start).unwrap() < timeout
|
|| start.elapsed() < timeout
|
||||||
})
|
})
|
||||||
.filter_map(|(_, entry)| entry.ok())
|
.filter_map(|(_, entry)| entry.ok())
|
||||||
.for_each(|entry| {
|
.for_each(|entry| {
|
||||||
@ -255,7 +255,7 @@ impl DirContents {
|
|||||||
|
|
||||||
log::trace!(
|
log::trace!(
|
||||||
"Building HashSets of directory files, folders and extensions took {:?}",
|
"Building HashSets of directory files, folders and extensions took {:?}",
|
||||||
SystemTime::now().duration_since(start).unwrap()
|
start.elapsed()
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(DirContents {
|
Ok(DirContents {
|
||||||
|
Loading…
Reference in New Issue
Block a user