1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// =============================================================================
// Copyright (c) 2026 Haixing Hu.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0.
// =============================================================================
//! Dispatches temporary-resource checks through the typed catalog.
use super::FileSystemCapability;
use super::FileSystemContractSuite;
use crate::ContractCheckId;
use crate::ContractCheckOutcome;
impl<'a> FileSystemContractSuite<'a> {
/// Executes all synchronous temporary-resource checks in catalog order.
///
/// # Returns
///
/// `Ok(())` after every temporary-resource entry has been recorded.
///
/// # Errors
///
/// Returns the first failure reported while executing a temporary-resource
/// entry.
pub(super) fn check_temp_resources(&mut self) -> Result<(), crate::ContractFailure> {
for id in [
ContractCheckId::TempFile,
ContractCheckId::TempDirectory,
ContractCheckId::TempAtomic,
ContractCheckId::TempRepeatedLifecycle,
] {
self.check_temp_item(id)?;
}
Ok(())
}
/// Executes exactly one temporary-resource catalog entry.
///
/// # Parameters
///
/// * `id` - Catalog entry identifying the temporary-resource scenario.
///
/// # Returns
///
/// `Ok(())` after the selected entry has been recorded.
///
/// # Errors
///
/// Returns a failure if `id` is not a temporary-resource entry or its
/// scenario fails.
pub(super) fn check_temp_item(&mut self, id: ContractCheckId) -> Result<(), crate::ContractFailure> {
self.context.begin_check(id);
let file = self.capable(FileSystemCapability::TempFile);
let directory = self.capable(FileSystemCapability::TempDirectory);
let outcome = match id {
ContractCheckId::TempFile => {
self.execute_temp_file(id)?;
if file {
ContractCheckOutcome::Passed
} else {
ContractCheckOutcome::RejectedAsExpected
}
}
ContractCheckId::TempDirectory => {
self.execute_temp_directory(id)?;
if directory {
ContractCheckOutcome::Passed
} else {
ContractCheckOutcome::RejectedAsExpected
}
}
ContractCheckId::TempAtomic | ContractCheckId::TempRepeatedLifecycle => {
if file {
self.execute_temp_file(id)?;
}
if directory {
self.execute_temp_directory(id)?;
}
if !file && !directory {
ContractCheckOutcome::NotApplicable {
reason: "no temporary resource capability".to_owned(),
}
} else if id == ContractCheckId::TempAtomic && !self.capable(FileSystemCapability::AtomicTempPersist) {
ContractCheckOutcome::RejectedAsExpected
} else {
ContractCheckOutcome::Passed
}
}
_ => {
return Err(crate::ContractFailure::message_only("selected entry is not temporary lifecycle").at(id));
}
};
let outcome = self
.context
.report()
.checks()
.iter()
.find(|check| check.id() == id)
.and_then(|check| match check.outcome() {
ContractCheckOutcome::Unverified { reason } => {
Some(ContractCheckOutcome::Unverified { reason: reason.clone() })
}
_ => None,
})
.unwrap_or(outcome);
self.context.record_check(
id,
crate::internal::check_catalog::specification(id).capability,
outcome,
);
Ok(())
}
}