mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 10:51:11 +01:00
Scripts: folder listings take their time limit from the session's clock
script::folder::list and script::startup::list measured the 250 ms listing limit (MAX_SCAN) with a real Instant. script.listInstalled, script.startup.run and the File > Scripts menu read the folders through them, so a test that went through any of these got a truncated listing and missing scripts whenever the disk stalled for 250 ms. - folder::Clock is either Wall (the real time since the listing started, the default) or Fixed (the same time at every check). Both list functions take one. - Session::set_script_listing_clock sets the clock the two commands and the menu's listing job use; the app keeps the real clock. - The script folder, startup script, scripts menu, script run and Safe Mode tests list with a fixed zero time, so a slow disk cannot cut a listing short. Direct listing calls use the test file's list helper. - New tests check that script.listInstalled, script.startup.run and the menu stop at the session's clock once it is past the limit and list everything at the limit.
This commit is contained in:
1 parent
5d70217e0c
commit
a354d09af4
11 files changed
+120
-25
No files matched your search
@@ -50,6 +50,30 @@ impl Default for Limits {
|
||||
}
|
||||
}
|
||||
|
||||
/// How a listing measures the time it has taken, which [`Limits::time`] bounds.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
pub enum Clock {
|
||||
/// The real time since the listing started.
|
||||
#[default]
|
||||
Wall,
|
||||
/// The same time at every check, whatever the real time: the listing reaches the time limit
|
||||
/// only when this time is past it.
|
||||
Fixed(Duration),
|
||||
}
|
||||
|
||||
impl Clock {
|
||||
/// Calls `f` with this clock's time since `f` was called.
|
||||
pub fn time<T>(self, f: impl FnOnce(&mut dyn FnMut() -> Duration) -> T) -> T {
|
||||
match self {
|
||||
Clock::Wall => {
|
||||
let start = std::time::Instant::now();
|
||||
f(&mut || start.elapsed())
|
||||
}
|
||||
Clock::Fixed(elapsed) => f(&mut || elapsed),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// One row of a listing.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum Entry {
|
||||
@@ -93,11 +117,10 @@ impl Listing {
|
||||
}
|
||||
}
|
||||
|
||||
/// What the folder `root` holds, within the default [`Limits`]. A folder that does not exist gives
|
||||
/// an empty listing.
|
||||
pub fn list(root: &Path) -> Listing {
|
||||
let start = std::time::Instant::now();
|
||||
list_with(root, &Limits::default(), &mut || start.elapsed())
|
||||
/// What the folder `root` holds, within the default [`Limits`], with the time measured by `clock`.
|
||||
/// A folder that does not exist gives an empty listing.
|
||||
pub fn list(root: &Path, clock: Clock) -> Listing {
|
||||
clock.time(|elapsed| list_with(root, &Limits::default(), elapsed))
|
||||
}
|
||||
|
||||
/// What the folder `root` holds, within `limits`; `elapsed` says how long the listing has taken.
|
||||
|
||||
@@ -37,11 +37,10 @@ pub fn takes(name: &str) -> bool {
|
||||
&& Path::new(name).extension().and_then(|e| e.to_str()).is_some_and(|e| e.eq_ignore_ascii_case("jsx"))
|
||||
}
|
||||
|
||||
/// The startup scripts in `root`, within the Scripts folder's limits. A folder that does not exist
|
||||
/// gives an empty listing.
|
||||
pub fn list(root: &Path) -> Listing {
|
||||
let start = std::time::Instant::now();
|
||||
list_with(root, &folder::Limits::default(), &mut || start.elapsed())
|
||||
/// The startup scripts in `root`, within the Scripts folder's limits, with the time measured by
|
||||
/// `clock`. A folder that does not exist gives an empty listing.
|
||||
pub fn list(root: &Path, clock: folder::Clock) -> Listing {
|
||||
clock.time(|elapsed| list_with(root, &folder::Limits::default(), elapsed))
|
||||
}
|
||||
|
||||
/// The startup scripts in `root`, within `limits` (the entries, scripts and time ones);
|
||||
|
||||
Reference in new issue
Block a user