Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tahoe-directory
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
PrivateStorage
tahoe-directory
Commits
f19a13f9
Commit
f19a13f9
authored
2 years ago
by
Jean-Paul Calderone
Browse files
Options
Downloads
Patches
Plain Diff
doodles
parent
f11c103f
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Tahoe/Directory/Internal/Parsing.hs
+15
-1
15 additions, 1 deletion
src/Tahoe/Directory/Internal/Parsing.hs
src/Tahoe/Directory/Internal/Types.hs
+4
-4
4 additions, 4 deletions
src/Tahoe/Directory/Internal/Types.hs
test/Spec.hs
+11
-0
11 additions, 0 deletions
test/Spec.hs
with
30 additions
and
5 deletions
src/Tahoe/Directory/Internal/Parsing.hs
+
15
−
1
View file @
f19a13f9
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FunctionalDependencies #-}
-- | Parsing and serialization for directories and their entries.
module
Tahoe.Directory.Internal.Parsing
where
...
...
@@ -13,12 +16,15 @@ import Text.Megaparsec.Byte (string)
import
Text.Megaparsec.Byte.Lexer
(
decimal
)
-- | Parse the serialized form of a directory into a Directory.
parse
::
B
.
ByteString
->
Either
(
ParseError
Bundle
B
.
ByteString
Void
)
Directory
parse
::
B
.
ByteString
->
Either
ParseError
Directory
parse
=
Text
.
Megaparsec
.
parse
pDirectory
"Directory"
-- | The parser type we will parse in.
type
Parser
=
Parsec
Void
B
.
ByteString
-- | The type for parse errors.
type
ParseError
=
ParseErrorBundle
B
.
ByteString
Void
-- XXX This doesn't do bounds checking.
-- | Parse the base ten representation of a natural number.
...
...
@@ -85,3 +91,11 @@ netstring xs =
,
xs
,
","
]
class
ReadCapability
c
s
m
|
c
->
s
where
read
::
c
->
[
s
]
->
m
B
.
ByteString
data
CapabilityParser
=
forall
c
.
CapabilityParser
(
Parser
c
)
parserWithCapabilities
::
ReadCapability
c
s
m
=>
[
Parser
c
]
->
Parser
(
Directory
c
s
(
m
a
))
parserWithCapabilities
parsers
=
undefined
This diff is collapsed.
Click to expand it.
src/Tahoe/Directory/Internal/Types.hs
+
4
−
4
View file @
f19a13f9
...
...
@@ -4,17 +4,17 @@ import qualified Data.ByteString as B
import
qualified
Data.Text
as
T
-- | A collection of references to other objects.
newtype
Directory
=
Directory
{
directoryChildren
::
[
Entry
]
newtype
Directory
c
s
m
=
Directory
{
directoryChildren
::
[
Entry
c
s
m
]
}
deriving
(
Eq
,
Show
)
-- | A reference to an object of any kind.
data
Entry
=
Entry
data
Entry
c
s
m
=
Entry
{
-- | The name of this entry in its containing directory. XXX What if UTF-8 decoding fails?
entryName
::
T
.
Text
,
-- | A capability for reading the contents of this entry. XXX Structured cap instead
entryReader
::
B
.
ByteString
entryReader
::
c
,
-- | An encrypted capability for performing writes to this entry. XXX
-- Document the encryption scheme.
entryEncryptedWriter
::
B
.
ByteString
...
...
This diff is collapsed.
Click to expand it.
test/Spec.hs
+
11
−
0
View file @
f19a13f9
...
...
@@ -9,6 +9,16 @@ import Test.Tasty (TestTree, defaultMain, testGroup)
import
Test.Tasty.HUnit
(
assertEqual
,
testCase
)
import
Test.Tasty.Hedgehog
(
testProperty
)
data
CapabilityType
c
=
Verify
(
Parser
c
)
|
Read
(
Parser
c
)
|
Write
(
Parser
c
)
chk
::
[
CapabilityType
]
chk
=
[
Verify
CHK
.
pVerifier
,
Read
CHK
.
pReader
]
sdmf
::
[
CapabilityType
]
sdmf
=
[
Verify
SDMF
.
pVerifier
,
Read
SDMF
.
pReader
,
Write
SDMF
.
pWriter
]
capParsers
=
chk
<>
sdmf
tests
::
TestTree
tests
=
testGroup
...
...
@@ -16,6 +26,7 @@ tests =
[
testCase
"well-known serialized directory round-trips through parse . serialize"
$
do
original
<-
B
.
readFile
"test/example.dir"
let
parsed
=
Directory
.
parse
original
parsed'
=
Directory
.
parseWithCapabilities
capParsers
original
serialized
=
Directory
.
serialize
<$>
parsed
assertEqual
"original /= serialized"
(
Right
original
)
serialized
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment