Skip to content

Instantly share code, notes, and snippets.

@dmwit
Created December 2, 2019 18:15
Show Gist options
  • Save dmwit/20b885f189e037df6c3e5eeba91774e8 to your computer and use it in GitHub Desktop.
Save dmwit/20b885f189e037df6c3e5eeba91774e8 to your computer and use it in GitHub Desktop.
find fp = do
entry <- entityFromFile fp
mold <- lookupEntity (entityHash entry)
pure $ case mold of
Nothing -> ImportAdded entry
Just old | entityPath old == entityPath entry -> ImportUpToDate entry
_ -> ImportMoved old entry
act (ImportAdded entry) = do
dbPutEntity entry
forM_ (entityPath entry) $ flip dbPutPath entry
act (ImportUpToDate entry) = pure ()
act (ImportMoved old entry) = do
dbPutEntity old { entityPath = entityPath entry }
forM_ (entityPath old) $ dbDel . asPathKey
forM_ (entityPath entry) $ \path -> do
unlinkPath path
dbPutPath path entry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment