Skip to content

Commit

Permalink
invalidate version cache on rhai scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettMayson committed Sep 27, 2023
1 parent 73bf643 commit dd22519
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
14 changes: 11 additions & 3 deletions bin/src/config/project/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ pub struct Options {
git_hash: Option<u8>,
}

static mut VERSION: MaybeUninit<Version> = MaybeUninit::uninit();
static mut INIT: bool = false;

impl Options {
/// Get the version of the project
///
Expand All @@ -33,9 +36,6 @@ impl Options {
/// Returns an error if the version is not a valid semver version
/// or a points to a file that does not contain a valid version macro
pub fn get(&self) -> Result<Version, Error> {
static mut VERSION: MaybeUninit<Version> = MaybeUninit::uninit();
static mut INIT: bool = false;

// Check for a cached version
unsafe {
if INIT {
Expand All @@ -59,6 +59,14 @@ impl Options {
}
}

/// Invalidate the cached version
#[allow(clippy::unused_self)]
pub fn invalidate(&self) {
unsafe {
INIT = false;
}
}

fn _get(&self) -> Result<Version, Error> {
// Check for a defined major version
if let Some(major) = self.major {
Expand Down
7 changes: 5 additions & 2 deletions bin/src/modules/hook/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ impl Hooks {
&std::fs::read_to_string(file.path())?,
vfs,
)?;
ctx.config().version().invalidate();
}
Ok(())
}
Expand All @@ -115,12 +116,14 @@ impl Hooks {
if !path.exists() {
return Err(Error::ScriptNotFound(name.to_owned()));
}
Self::run(
let res = Self::run(
ctx,
name.to_string(),
&std::fs::read_to_string(path)?,
false,
)
);
ctx.config().version().invalidate();
res
}

fn run(ctx: &Context, name: String, script: &str, vfs: bool) -> Result<(), Error> {
Expand Down

0 comments on commit dd22519

Please sign in to comment.