@@ -242,6 +242,7 @@ runModelMWithInjectedErrors (Just _) _ onErrors st =
242242
243243data Err =
244244 ErrTableClosed
245+ | ErrSnapshotCorrupted
245246 | ErrSnapshotExists
246247 | ErrSnapshotDoesNotExist
247248 | ErrSnapshotWrongType
@@ -254,6 +255,8 @@ instance Show Err where
254255 showsPrec d = \ case
255256 ErrTableClosed ->
256257 showString " ErrTableClosed"
258+ ErrSnapshotCorrupted ->
259+ showString " ErrSnapshotCorrupted"
257260 ErrSnapshotExists ->
258261 showString " ErrSnapshotExists"
259262 ErrSnapshotDoesNotExist ->
@@ -271,6 +274,7 @@ instance Show Err where
271274
272275instance Eq Err where
273276 (==) ErrTableClosed ErrTableClosed = True
277+ (==) ErrSnapshotCorrupted ErrSnapshotCorrupted = True
274278 (==) ErrSnapshotExists ErrSnapshotExists = True
275279 (==) ErrSnapshotDoesNotExist ErrSnapshotDoesNotExist = True
276280 (==) ErrSnapshotWrongType ErrSnapshotWrongType = True
@@ -281,6 +285,7 @@ instance Eq Err where
281285 where
282286 _coveredAllCases x = case x of
283287 ErrTableClosed {} -> ()
288+ ErrSnapshotCorrupted {} -> ()
284289 ErrSnapshotExists {} -> ()
285290 ErrSnapshotDoesNotExist {} -> ()
286291 ErrSnapshotWrongType {} -> ()
@@ -541,7 +546,12 @@ invalidateBlobRefs Table{..} = do
541546 Snapshots
542547-------------------------------------------------------------------------------}
543548
544- data Snapshot = Snapshot TableConfig SnapshotLabel SomeTable
549+ data Snapshot = Snapshot
550+ { snapshotConfig :: TableConfig
551+ , snapshotLabel :: SnapshotLabel
552+ , snapshotTable :: SomeTable
553+ , snapshotCorrupted :: Bool
554+ }
545555 deriving stock Show
546556
547557createSnapshot ::
@@ -559,7 +569,7 @@ createSnapshot label name t@Table{..} = do
559569 when (Map. member name snaps) $
560570 throwError ErrSnapshotExists
561571 modify (\ m -> m {
562- snapshots = Map. insert name (Snapshot config label $ toSomeTable $ Model. snapshot table) (snapshots m)
572+ snapshots = Map. insert name (Snapshot config label ( toSomeTable $ Model. snapshot table) False ) (snapshots m)
563573 })
564574
565575openSnapshot ::
@@ -576,7 +586,9 @@ openSnapshot label name = do
576586 case Map. lookup name snaps of
577587 Nothing ->
578588 throwError ErrSnapshotDoesNotExist
579- Just (Snapshot conf label' tbl) -> do
589+ Just (Snapshot conf label' tbl corrupted) -> do
590+ when corrupted $
591+ throwError ErrSnapshotCorrupted
580592 when (label /= label') $
581593 throwError ErrSnapshotWrongType
582594 case fromSomeTable tbl of
@@ -596,7 +608,12 @@ corruptSnapshot ::
596608 => SnapshotName
597609 -> m ()
598610corruptSnapshot name = do
599- undefined
611+ snapshots <- gets snapshots
612+ if Map. notMember name snapshots
613+ then throwError ErrSnapshotDoesNotExist
614+ else modify $ \ m -> m {snapshots = Map. adjust corruptSnapshotEntry name snapshots}
615+ where
616+ corruptSnapshotEntry (Snapshot c l t _) = Snapshot c l t True
600617
601618deleteSnapshot ::
602619 (MonadState Model m , MonadError Err m )
0 commit comments