diff options
Diffstat (limited to 'examples/FS.hs')
-rw-r--r-- | examples/FS.hs | 74 |
1 files changed, 0 insertions, 74 deletions
diff --git a/examples/FS.hs b/examples/FS.hs deleted file mode 100644 index 550d85a7..00000000 --- a/examples/FS.hs +++ /dev/null | |||
@@ -1,74 +0,0 @@ | |||
1 | {-# LANGUAGE RecordWildCards #-} | ||
2 | module Main (main) where | ||
3 | |||
4 | import Control.Arrow | ||
5 | import Data.ByteString.Char8 as BC | ||
6 | import Data.List as L | ||
7 | import Data.Map as M | ||
8 | import Data.Torrent as T | ||
9 | import Data.Torrent.Tree as T | ||
10 | import System.Environment | ||
11 | import System.Fuse | ||
12 | import System.FilePath | ||
13 | import System.Posix.Files | ||
14 | |||
15 | |||
16 | defStat :: FileStat | ||
17 | defStat = FileStat | ||
18 | { statEntryType = Unknown | ||
19 | , statFileMode = ownerReadMode | ||
20 | , statLinkCount = 2 | ||
21 | |||
22 | , statFileOwner = 0 | ||
23 | , statFileGroup = 0 | ||
24 | |||
25 | , statSpecialDeviceID = 0 | ||
26 | |||
27 | , statFileSize = 0 | ||
28 | , statBlocks = 0 | ||
29 | |||
30 | , statAccessTime = 0 | ||
31 | , statModificationTime = 0 | ||
32 | , statStatusChangeTime = 0 | ||
33 | } | ||
34 | |||
35 | dirStat :: FileStat | ||
36 | dirStat = defStat { | ||
37 | statEntryType = Directory | ||
38 | } | ||
39 | |||
40 | type Result a = IO (Either Errno a) | ||
41 | type Result' = IO Errno | ||
42 | |||
43 | fsGetFileStat :: Torrent -> FilePath -> Result FileStat | ||
44 | fsGetFileStat _ path = return $ Right dirStat | ||
45 | |||
46 | fsOpenDirectory :: Torrent -> FilePath -> Result' | ||
47 | fsOpenDirectory _ _ = return eOK | ||
48 | |||
49 | fsReadDirectory :: Torrent -> FilePath -> Result [(FilePath, FileStat)] | ||
50 | fsReadDirectory Torrent {tInfoDict = InfoDict {..}} path | ||
51 | | Just cs <- T.lookupDir (L.tail (splitDirectories path)) tree = | ||
52 | return $ Right $ L.map (BC.unpack *** const defStat) cs | ||
53 | | otherwise = return $ Left eNOENT | ||
54 | where | ||
55 | tree = build $ idLayoutInfo | ||
56 | |||
57 | fsReleaseDirectory :: Torrent -> FilePath -> Result' | ||
58 | fsReleaseDirectory _ _ = return eOK | ||
59 | |||
60 | exfsOps :: Torrent -> FuseOperations () | ||
61 | exfsOps t = defaultFuseOps | ||
62 | { fuseGetFileStat = fsGetFileStat t | ||
63 | |||
64 | , fuseOpenDirectory = fsOpenDirectory t | ||
65 | , fuseReadDirectory = fsReadDirectory t | ||
66 | , fuseReleaseDirectory = fsReleaseDirectory t | ||
67 | } | ||
68 | |||
69 | main :: IO () | ||
70 | main = do | ||
71 | x : xs <- getArgs | ||
72 | t <- fromFile x | ||
73 | withArgs xs $ do | ||
74 | fuseMain (exfsOps t) defaultExceptionHandler \ No newline at end of file | ||