@@ -140,4 +140,39 @@ impl FsProofStorage {
140140
141141 Ok ( Proof ( Arc :: new ( proof_data) ) )
142142 }
143+
144+ fn write_proof_atomically ( & self , facts_hash : Felt , proof : Proof ) -> FsProofStorageResult < ( ) > {
145+ // Write proof to a temporary directory.
146+ let ( _tmp_root, tmp_dir) = self . create_tmp_dir ( facts_hash) ?;
147+ self . write_proof_to_file ( & tmp_dir, & proof) ?;
148+
149+ // Atomically rename directory to persistent one.
150+ let persistent_dir = self . get_persistent_dir_with_create ( facts_hash) ?;
151+ std:: fs:: rename ( tmp_dir, persistent_dir) ?;
152+ Ok ( ( ) )
153+ }
154+ }
155+
156+ impl ProofStorage for FsProofStorage {
157+ type Error = FsProofStorageError ;
158+
159+ fn set_proof ( & self , facts_hash : Felt , proof : Proof ) -> Result < ( ) , Self :: Error > {
160+ self . write_proof_atomically ( facts_hash, proof) ?;
161+ Ok ( ( ) )
162+ }
163+
164+ fn get_proof ( & self , facts_hash : Felt ) -> Result < Option < Proof > , Self :: Error > {
165+ if !self . contains_proof ( facts_hash) ? {
166+ return Ok ( None ) ;
167+ }
168+
169+ match self . read_proof_from_file ( facts_hash) {
170+ Ok ( proof) => Ok ( Some ( proof) ) ,
171+ Err ( e) => Err ( e) ,
172+ }
173+ }
174+
175+ fn contains_proof ( & self , facts_hash : Felt ) -> Result < bool , Self :: Error > {
176+ Ok ( self . get_persistent_dir ( facts_hash) . exists ( ) )
177+ }
143178}
0 commit comments