File tree Expand file tree Collapse file tree 3 files changed +63
-4
lines changed Expand file tree Collapse file tree 3 files changed +63
-4
lines changed Original file line number Diff line number Diff line change @@ -6,13 +6,25 @@ import (
6
6
7
7
// Path is a generic wrapper for paths used in the API. A path can be resolved
8
8
// to a CID using one of Resolve functions in the API.
9
- // TODO: figure out/explain namespaces
9
+ //
10
+ // Paths must be prefixed with a valid prefix:
11
+ //
12
+ // * /ipfs - Immutable unixfs path (files)
13
+ // * /ipld - Immutable ipld path (data)
14
+ // * /ipns - Mutable names. Usually resolves to one of the immutable paths
15
+ //TODO: /local (MFS)
10
16
type Path interface {
11
17
// String returns the path as a string.
12
18
String () string
13
19
14
20
// Namespace returns the first component of the path
15
21
Namespace () string
22
+
23
+ // Mutable returns false if the data pointed to by this path in guaranteed
24
+ // to not change.
25
+ //
26
+ // Note that resolved mutable path can be immutable.
27
+ Mutable () bool
16
28
}
17
29
18
30
// ResolvedPath is a resolved Path
Original file line number Diff line number Diff line change @@ -97,13 +97,26 @@ func (api *CoreAPI) ParsePath(p string) (coreiface.Path, error) {
97
97
return & path {path : pp }, nil
98
98
}
99
99
100
- func (p * path ) String () string { return p .path .String () }
100
+ func (p * path ) String () string {
101
+ return p .path .String ()
102
+ }
103
+
101
104
func (p * path ) Namespace () string {
102
105
if len (p .path .Segments ()) < 1 {
103
106
return ""
104
107
}
105
108
return p .path .Segments ()[0 ]
106
109
}
107
110
108
- func (p * resolvedPath ) Cid () * cid.Cid { return p .cid }
109
- func (p * resolvedPath ) Root () * cid.Cid { return p .root }
111
+ func (p * path ) Mutable () bool {
112
+ //TODO: MFS: check for /local
113
+ return p .Namespace () == "ipns"
114
+ }
115
+
116
+ func (p * resolvedPath ) Cid () * cid.Cid {
117
+ return p .cid
118
+ }
119
+
120
+ func (p * resolvedPath ) Root () * cid.Cid {
121
+ return p .root
122
+ }
Original file line number Diff line number Diff line change
1
+ package coreapi_test
2
+
3
+ import (
4
+ "context"
5
+ "strings"
6
+ "testing"
7
+ )
8
+
9
+ func TestMutablePath (t * testing.T ) {
10
+ ctx := context .Background ()
11
+ _ , api , err := makeAPI (ctx )
12
+ if err != nil {
13
+ t .Fatal (err )
14
+ }
15
+
16
+ // get self /ipns path
17
+ keys , err := api .Key ().List (ctx )
18
+ if err != nil {
19
+ t .Fatal (err )
20
+ }
21
+
22
+ if ! keys [0 ].Path ().Mutable () {
23
+ t .Error ("expected self /ipns path to be mutable" )
24
+ }
25
+
26
+ blk , err := api .Block ().Put (ctx , strings .NewReader (`foo` ))
27
+ if err != nil {
28
+ t .Error (err )
29
+ }
30
+
31
+ if blk .Mutable () {
32
+ t .Error ("expected /ipld path to be immutable" )
33
+ }
34
+ }
You can’t perform that action at this time.
0 commit comments