You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// TODO: somehow account for old versions that are not compatible with the store struct
399
421
if store.version != Version::CURRENT{
400
422
warn!("The store that was loaded is not of the current version: store has {} but the current version is {}", store.version,Version::CURRENT);
401
423
ifVersion::SUPPROTED.contains(&store.version){
402
-
warn!("The old store version is still supported, migrating to newer version");
424
+
warn!("The different store version is still supported, migrating to newer version");
403
425
warn!("Temp migration in memory, can be made permanent by saving");
404
426
427
+
if store.version > Version::CURRENT{
428
+
warn!("The store version is newer than this version of netpulse can normally handle! Trying to ignore potential differences and loading as READONLY!");
429
+
store.readonly = true;
430
+
}
431
+
405
432
while store.version < Version::CURRENT{
406
433
for check in store.checks_mut().iter_mut(){
407
434
ifletErr(e) = check.migrate(Version::V0){
@@ -437,8 +464,12 @@ impl Store {
437
464
/// - File doesn't exist
438
465
/// - Write fails
439
466
/// - Serialization fails
467
+
/// - Trying to save a readonly [Store]
440
468
pubfnsave(&self) -> Result<(),StoreError>{
441
469
info!("Saving the store");
470
+
ifself.readonly{
471
+
returnErr(StoreError::IsReadonly);
472
+
}
442
473
let file = match fs::File::options()
443
474
.read(false)
444
475
.write(true)
@@ -478,19 +509,45 @@ impl Store {
478
509
/// Returns the check interval in seconds.
479
510
///
480
511
/// This determines how frequently the daemon performs checks.
481
-
/// Currently fixed at 60 seconds.
482
-
pubconstfnperiod_seconds(&self) -> i64{
483
-
60
512
+
/// Default is [DEFAULT_PERIOD], but this value can be overridden by setting [ENV_PERIOD] as
513
+
/// environment variable.
514
+
pubfnperiod_seconds(&self) -> i64{
515
+
ifletOk(v) = std::env::var(ENV_PERIOD){
516
+
v.parse().unwrap_or(DEFAULT_PERIOD)
517
+
}else{
518
+
DEFAULT_PERIOD
519
+
}
484
520
}
485
521
486
-
/// Generates a hash of the in-memory store data.
522
+
/// Generates a cryptographic hash of the entire [Store].
523
+
///
524
+
/// Uses [blake3] for consistent hashing across Rust versions and platforms.
525
+
/// The hash changes when any check (or other field) in the store is modified,
526
+
/// added, or removed.
527
+
///
528
+
/// # Implementation Details
487
529
///
488
-
/// Uses [DefaultHasher](std::hash::DefaultHasher) to create a 16-character hexadecimal hash
489
-
/// of the entire store contents. Useful for detecting changes.
0 commit comments