Browse files

Fixed the brokenness, shell now works! Also changed showHash to outpu…

…t in hex rather than Base64, for easy comparison with hex dumps of files.
  • Loading branch information...
1 parent 94a30a7 commit 4dca49c03a6647340e8fffc99e9a4d58b611e5b8 @luqui committed Nov 18, 2008
Showing with 12 additions and 9 deletions.
  1. +5 −4 udon/Udon/DataDesc.hs
  2. +5 −3 udon/Udon/Database.hs
  3. +2 −2 udon/Udon/Hash.hs
View
9 udon/Udon/DataDesc.hs
@@ -2,7 +2,7 @@ module Udon.DataDesc
( ExtRef, extRefHash, unsafeExtRefValue, unsafeMakeExtRef, makeExtRef
, DataDesc, ddDump, ddRead
, Data(..)
- , Dump(..)
+ , Dump(..), hashDump
, pure, sequ, ref, binary
)
where
@@ -31,9 +31,10 @@ makeExtRef :: (Data a) => a -> ExtRef a
makeExtRef x = unsafeMakeExtRef (hashDesc x) (Just x)
hashDesc :: (Data a) => a -> Hash
-hashDesc x = hashBlob . encode . snd . runChunkPut $ put
- where
- Dump put _ = ddDump desc x
+hashDesc = hashDump . ddDump desc
+
+hashDump :: Dump -> Hash
+hashDump (Dump rput _) = hashBinary . snd . runChunkPut $ rput
data DataDesc a
= DataDesc { ddDump :: a -> Dump
View
8 udon/Udon/Database.hs
@@ -48,8 +48,8 @@ writeChunk db chunk = store db (hashBlob enc) enc
enc = encode chunk
writeDump :: (Monad m) => Database m -> Dump -> m Hash
-writeDump db = \dump@(Dump rput _) -> do
- let hash = hashBinary . snd . runChunkPut $ rput
+writeDump db = \dump -> do
+ let hash = hashDump dump
go hash dump
return hash
where
@@ -91,7 +91,9 @@ writeData db x = writeDump db (ddDump desc x)
-- is done with extref, but that has proven pretty tricky to do.
makeDynRef :: (Monad m, Data a) => Database m -> DynType a -> ExtRef a -> m DynRef
makeDynRef db dyntype ref = do
- hash <- writeData db (unsafeExtRefValue ref)
+ case unsafeExtRefValue ref of
+ Nothing -> return ()
+ Just v -> writeData db v >> return ()
return $ unsafeExtRefToDynRef dyntype ref
exportDyn :: (Monad m) => Database m -> DynRef -> m ExportRef
View
4 udon/Udon/Hash.hs
@@ -5,15 +5,15 @@ where
import qualified Data.ByteString.Lazy as Str
import qualified Data.Digest.SHA256 as SHA
import Data.Binary
-import qualified Codec.Binary.Base64Url as Base64
+import qualified Codec.Binary.Base16 as Base16
type Blob = Str.ByteString
newtype Hash = Hash Blob
deriving (Eq,Ord)
showHash :: Hash -> String
-showHash (Hash blob) = Base64.encode (Str.unpack blob)
+showHash (Hash blob) = Base16.encode . Str.unpack $ blob
-- Not an instance of binary so that we can't accidentally write
-- a hash without referencing it in the Chunk structure.

0 comments on commit 4dca49c

Please sign in to comment.