@@ -63,6 +63,7 @@ module Database.LSMTree.Internal (
6363 , createSnapshot
6464 , openSnapshot
6565 , deleteSnapshot
66+ , doesSnapshotExist
6667 , listSnapshots
6768 -- * Multiple writable tables
6869 , duplicate
@@ -1209,9 +1210,8 @@ createSnapshot snap label tableType t = do
12091210
12101211 -- Guard that the snapshot does not exist already
12111212 let snapDir = Paths. namedSnapshotDir (tableSessionRoot tEnv) snap
1212- doesSnapshotExist <-
1213- FS. doesDirectoryExist (tableHasFS tEnv) (Paths. getNamedSnapshotDir snapDir)
1214- if doesSnapshotExist then
1213+ snapshotExists <- doesSnapshotDirExist snap (tableSessionEnv tEnv)
1214+ if snapshotExists then
12151215 throwIO (ErrSnapshotExists snap)
12161216 else
12171217 -- we assume the snapshots directory already exists, so we just have
@@ -1342,6 +1342,24 @@ openSnapshot sesh label tableType override snap resolve = do
13421342 , tableUnionLevel = unionLevel
13431343 }
13441344
1345+ {-# SPECIALISE doesSnapshotExist ::
1346+ Session IO h
1347+ -> SnapshotName
1348+ -> IO Bool #-}
1349+ -- | See 'Database.LSMTree.Common.doesSnapshotExist'.
1350+ doesSnapshotExist ::
1351+ (MonadMask m , MonadSTM m )
1352+ => Session m h
1353+ -> SnapshotName
1354+ -> m Bool
1355+ doesSnapshotExist sesh snap = withOpenSession sesh (doesSnapshotDirExist snap)
1356+
1357+ -- | Internal helper: Variant of 'doesSnapshotExist' that does not take a session lock.
1358+ doesSnapshotDirExist :: SnapshotName -> SessionEnv m h -> m Bool
1359+ doesSnapshotDirExist snap seshEnv = do
1360+ let snapDir = Paths. namedSnapshotDir (sessionRoot seshEnv) snap
1361+ FS. doesDirectoryExist (sessionHasFS seshEnv) (Paths. getNamedSnapshotDir snapDir)
1362+
13451363{-# SPECIALISE deleteSnapshot ::
13461364 Session IO h
13471365 -> SnapshotName
@@ -1355,13 +1373,10 @@ deleteSnapshot ::
13551373deleteSnapshot sesh snap = do
13561374 traceWith (sessionTracer sesh) $ TraceDeleteSnapshot snap
13571375 withOpenSession sesh $ \ seshEnv -> do
1358- let hfs = sessionHasFS seshEnv
1359-
13601376 let snapDir = Paths. namedSnapshotDir (sessionRoot seshEnv) snap
1361- doesSnapshotExist <-
1362- FS. doesDirectoryExist (sessionHasFS seshEnv) (Paths. getNamedSnapshotDir snapDir)
1363- unless doesSnapshotExist $ throwIO (ErrSnapshotDoesNotExist snap)
1364- FS. removeDirectoryRecursive hfs (Paths. getNamedSnapshotDir snapDir)
1377+ snapshotExists <- doesSnapshotDirExist snap seshEnv
1378+ unless snapshotExists $ throwIO (ErrSnapshotDoesNotExist snap)
1379+ FS. removeDirectoryRecursive (sessionHasFS seshEnv) (Paths. getNamedSnapshotDir snapDir)
13651380
13661381{-# SPECIALISE listSnapshots :: Session IO h -> IO [SnapshotName] #-}
13671382-- | See 'Database.LSMTree.Common.listSnapshots'.
0 commit comments