finish: only close cursor if cursor-id is non-zero

A '0' cursor-id means that no cursor was created, so there's nothing
to kill.

Also, findOne should never have a cursor opened for it, so no need
to even call finish.
This commit is contained in:
Scott R. Parish 2010-02-01 09:04:43 -06:00
parent 4c369f7a92
commit 9bc616ccf5

View file

@ -441,7 +441,6 @@ findOne :: Connection -> FullCollection -> Selector -> IO (Maybe BsonDoc)
findOne c col sel = do findOne c col sel = do
cur <- query c col [] 0 (-1) sel [] cur <- query c col [] 0 (-1) sel []
el <- nextDoc cur el <- nextDoc cur
finish cur
return el return el
-- | Perform a query and return the result as a lazy list. Be sure to -- | Perform a query and return the result as a lazy list. Be sure to
@ -629,6 +628,9 @@ finish :: Cursor -> IO ()
finish cur = do finish cur = do
let h = cHandle $ curCon cur let h = cHandle $ curCon cur
cid <- readIORef $ curID cur cid <- readIORef $ curID cur
if cid == 0
then return ()
else do
let body = runPut $ do let body = runPut $ do
putI32 0 putI32 0
putI32 1 putI32 1