[Fencommits] fenserve: prepare for using RDF: use Nodes instead of BlockIds to identify directories, so that we can have blk:...#dir
Benja Fallenstein
benja.fallenstein at gmail.com
Thu Mar 22 19:49:21 EET 2007
Sun Mar 18 15:47:56 EET 2007 Benja Fallenstein <benja.fallenstein at gmail.com>
* prepare for using RDF: use Nodes instead of BlockIds to identify directories, so that we can have blk:...#dir
diff -rN -u old-fenserve/FenServe.hs new-fenserve/FenServe.hs
--- old-fenserve/FenServe.hs 2007-03-22 19:49:20.000000000 +0200
+++ new-fenserve/FenServe.hs 2007-03-22 19:49:20.000000000 +0200
@@ -55,7 +55,9 @@
fs_language = IRI "http://fenfire.org/2007/fenserve#language"
rget :: Node -> Node -> Graph -> Node
-rget p s g = fromJust $ getOne g s p Pos
+rget p s g = fromMaybe (error $ "FenServe.rget: not found: " ++ show s
+ ++ " " ++ show p)
+ (getOne g s p Pos)
data Entry = DirEntry { entryName :: String, entrySubdir :: Node }
| FileEntry { entryName :: String, entryRepr :: Node } deriving (Show, Read)
@@ -63,9 +65,10 @@
data Directory = Dir { dirNode :: Node, dirEntries :: [Entry] } deriving (Show, Read)
emptyState :: Ptr
-emptyState = runStormIO (writeBlock (Dir (IRI "#dir") [])) Map.empty
+emptyState = runStormIO (liftM bIRI $ writeBlock (Dir (IRI "#dir") []))
+ Map.empty
-type Ptr = (BlockId, Pool)
+type Ptr = (Node, Pool)
instance ToRDF Directory where
toRDF (Dir node entries) = do
@@ -141,16 +144,16 @@
bID :: Node -> BlockId
bID (IRI ('b':'l':'k':':':s)) = BlockId $ takeWhile (/= '#') s
-readGraph :: BlockId -> StormIO Graph
-readGraph bid = liftM (setGraphURI $ bURI bid) $ readBlock bid
+readGraph :: Node -> StormIO Graph
+readGraph gNode = liftM (setGraphURI $ nodeStr gNode) $ readBlock (bID gNode)
-getURI :: [String] -> BlockId -> StormIO ByteString
-getURI [x] bid = readBlock bid >>= f . dirEntries where
+getURI :: [String] -> Node -> StormIO ByteString
+getURI [x] dir = readBlock (bID dir) >>= f . dirEntries where
f (FileEntry n r : _ ) | n == x = getBlock (bID r)
f (_ : es) = f es
f [] = return $ toUTF $ "not found: " ++ x
-getURI (x:xs) bid = readBlock bid >>= f . dirEntries where
- f (DirEntry n sub : _ ) | n == x = getURI xs (bID sub)
+getURI (x:xs) dir = readBlock (bID dir) >>= f . dirEntries where
+ f (DirEntry n sub : _ ) | n == x = getURI xs sub
f (_ : es) = f es
f [] = return $ toUTF $ "dir not found: " ++ x
@@ -161,20 +164,20 @@
in writeGraph graph' pool
-}
-updateData :: (Read a, Show a) => EndoM StormIO a -> EndoM StormIO BlockId
-updateData f bid = writeBlock =<< f =<< readBlock bid
+updateData :: (Read a, Show a) => EndoM StormIO a -> EndoM StormIO Node
+updateData f node = return . bIRI =<< writeBlock =<< f =<< readBlock (bID node)
-putURI :: [String] -> ByteString -> BlockId -> StormIO BlockId
-putURI path s bid = do rid <- addBlock s; putURI' path (bIRI rid) bid where
- putURI' [x] r bid = do updateData f' bid where
+putURI :: [String] -> ByteString -> Node -> StormIO Node
+putURI path s dir = do rid <- addBlock s; putURI' path (bIRI rid) dir where
+ putURI' [x] r dir = do updateData f' dir where
f' (Dir n entries) = return $ Dir n (f entries)
f (FileEntry n _ : es) | n == x = FileEntry n r : es
f (e : es) = e : f es
f [] = [FileEntry x r]
- putURI' (x:xs) r bid = updateData f' bid where
- recurse sub = do sub' <- putURI' xs r sub; return [DirEntry x (bIRI sub')]
+ putURI' (x:xs) r dir = updateData f' dir where
+ recurse sub = do sub' <- putURI' xs r sub; return [DirEntry x sub']
f' (Dir n entries) = do es' <- f entries; return (Dir n es')
- f (DirEntry n sub : es) | n == x = liftM (++es) (recurse $ bID sub)
+ f (DirEntry n sub : es) | n == x = liftM (++es) (recurse sub)
f (e : es) = do es' <- f es; return (e:es')
f [] = recurse (fst $ emptyState)
More information about the Fencommits
mailing list