summaryrefslogtreecommitdiffstats
path: root/src/context.rs
diff options
context:
space:
mode:
authorThomas O'Donnell <andytom@users.noreply.github.com>2020-10-17 21:36:21 +0200
committerGitHub <noreply@github.com>2020-10-17 15:36:21 -0400
commit035e80bbd3ba83ed97ff0c86308d20547f1ac311 (patch)
tree397f323f46cafb100e98ee447df50dfbbbb2a0f2 /src/context.rs
parent95bb901b8a4927fb50386a5c52a285392b60f90d (diff)
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.
Diffstat (limited to 'src/context.rs')
-rw-r--r--src/context.rs10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/context.rs b/src/context.rs
index de7b901d1..3f78375a4 100644
--- a/src/context.rs
+++ b/src/context.rs
@@ -11,7 +11,7 @@ use std::ffi::OsString;
use std::fs;
use std::path::{Path, PathBuf};
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.
/// 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> {
- let start = SystemTime::now();
+ let start = Instant::now();
let mut folders: HashSet<PathBuf> = HashSet::new();
let mut files: HashSet<PathBuf> = HashSet::new();
@@ -233,8 +233,8 @@ impl DirContents {
fs::read_dir(base)?
.enumerate()
.take_while(|(n, _)| {
- n & 0xFF != 0 // only check SystemTime once every 2^8 entries
- || SystemTime::now().duration_since(start).unwrap() < timeout
+ n & 0xFF != 0 // only check timeout once every 2^8 entries
+ || start.elapsed() < timeout
})
.filter_map(|(_, entry)| entry.ok())
.for_each(|entry| {
@@ -255,7 +255,7 @@ impl DirContents {
log::trace!(
"Building HashSets of directory files, folders and extensions took {:?}",
- SystemTime::now().duration_since(start).unwrap()
+ start.elapsed()
);
Ok(DirContents {