Skip to content
This repository was archived by the owner on Jun 19, 2023. It is now read-only.

Commit 9f28d54

Browse files
committed
WIP
1 parent 95220b3 commit 9f28d54

File tree

5 files changed

+109
-54
lines changed

5 files changed

+109
-54
lines changed

filesystem/interface/interface.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,25 @@ import (
1313

1414
type (
1515
ParseFn func(ctx context.Context, name string) (Node, error)
16-
Kind int
17-
Flag string
18-
Flags []struct{Flag;bool}
16+
Kind int
17+
Flag string
18+
Flags []struct {
19+
Flag
20+
bool
21+
}
1922
)
2023

2124
const (
22-
FRead Flag ="File Read"
23-
FWrite = "File Write"
24-
FSync = "File Sync"
25+
FRead Flag = "File Read"
26+
FWrite = "File Write"
27+
FSync = "File Sync"
2528
)
2629

2730
const (
28-
UfsFile = Kind(unixfs.TFile)
31+
UfsFile = Kind(unixfs.TFile)
2932
UfsDirectory = Kind(unixfs.TDirectory)
30-
UfsHAMT = Kind(unixfs.THAMTShard)
31-
UfsSymlink = Kind(unixfs.TSymlink)
33+
UfsHAMT = Kind(unixfs.THAMTShard)
34+
UfsSymlink = Kind(unixfs.TSymlink)
3235
)
3336

3437
type FsError interface {
@@ -48,7 +51,8 @@ var (
4851
ErrRoot = FsError(errors.New("root initialization exception"))
4952
ErrRecurse = FsError(errors.New("hit recursion limit"))
5053
//
51-
ErrNoHandler = FsError(errors.New("no handler registered for this request"))
54+
ErrNoHandler = FsError(errors.New("no handler registered for this request"))
55+
ErrNotImplemented = FsError(errors.New("operation not implemented"))
5256
)
5357

5458
// Provides standard convention wrappers around an index

filesystem/node/soft/base.go

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package fsnode
22

33
import (
44
"context"
5+
"strings"
56
"sync"
67

78
"github.com/billziss-gh/cgofuse/fuse"
@@ -11,7 +12,7 @@ import (
1112

1213
type BaseNode struct {
1314
sync.RWMutex
14-
path string
15+
path string
1516
version uint
1617

1718
metadata Metadata
@@ -20,20 +21,20 @@ type BaseNode struct {
2021
// implementation of Metadata interface
2122
type Metadata struct {
2223
//apiPath string
23-
fStat fuse.Stat_t
24+
fStat fuse.Stat_t
2425
ipfsFlags fs.Flags
2526
}
2627

2728
func (md *Metadata) Type() fs.Kind {
28-
t := coreiface.TUnknown
29+
t := coreiface.TUnknown
2930

3031
switch md.fStat.Mode & fuse.S_IFMT {
3132
case fuse.S_IFREG:
32-
t= coreiface.TFile
33+
t = coreiface.TFile
3334
case fuse.S_IFDIR:
34-
t= coreiface.TDirectory
35+
t = coreiface.TDirectory
3536
case fuse.S_IFLNK:
36-
t= coreiface.TSymlink
37+
t = coreiface.TSymlink
3738
}
3839

3940
return fs.Kind(t)
@@ -48,7 +49,7 @@ func (md *Metadata) Size() uint {
4849
}
4950

5051
// conversion between fStat and interface
51-
func (rb *BaseNode) Metadata() (fs.Metadata, error) {
52+
func (rb *BaseNode) Metadata(_ context.Context) (fs.Metadata, error) {
5253
return &rb.metadata, nil
5354
}
5455

@@ -60,14 +61,35 @@ func (rb *BaseNode) String() string {
6061
return rb.path
6162
}
6263

63-
func (rb *BaseNode) Remove(_ context.Context) (int, error) {
64-
return -fuse.EROFS, fs.ErrReadOnly
64+
func (rb *BaseNode) Remove(_ context.Context) error {
65+
return fs.ErrNotImplemented
66+
}
67+
68+
func (rb *BaseNode) Create(_ context.Context, _ fs.Kind) error {
69+
return fs.ErrNotImplemented
70+
}
71+
72+
//Core API Path interface
73+
func (rb *BaseNode) IsValid() error {
74+
return fs.ErrNotImplemented
75+
}
76+
77+
func (rb *BaseNode) Mutable() bool {
78+
return false
79+
}
80+
81+
func (rb *BaseNode) Namespace() string {
82+
i := strings.IndexRune(rb.path[1:], '/')
83+
if i == -1 {
84+
return "root"
85+
}
86+
return rb.path[1:i]
6587
}
6688

6789
const (
6890
IRWXA = fuse.S_IRWXU | fuse.S_IRWXG | fuse.S_IRWXO
69-
IRXA = IRWXA &^ (fuse.S_IWUSR | fuse.S_IWGRP | fuse.S_IWOTH)
70-
)
91+
IRXA = IRWXA &^ (fuse.S_IWUSR | fuse.S_IWGRP | fuse.S_IWOTH)
92+
)
7193

7294
func (rb *BaseNode) InitMetadata(_ context.Context) (*fuse.Stat_t, error) {
7395
now := fuse.Now()
@@ -88,10 +110,14 @@ func (rb *BaseNode) typeCheck(nodeType fs.Kind) (err error) {
88110

89111
func typeCheck(pMode uint32, nodeType fs.Kind) bool {
90112
switch nodeType {
91-
case fs.UfsFile: return fuse.S_IFREG == (pMode & fuse.S_IFDIR)
92-
case fs.UfsDirectory: return fuse.S_IFDIR == (pMode & fuse.S_IFDIR)
93-
case fs.UfsSymlink: return fuse.S_IFLNK == (pMode & fuse.S_IFDIR)
94-
default: return false
113+
case fs.UfsFile:
114+
return fuse.S_IFREG == (pMode & fuse.S_IFDIR)
115+
case fs.UfsDirectory:
116+
return fuse.S_IFDIR == (pMode & fuse.S_IFDIR)
117+
case fs.UfsSymlink:
118+
return fuse.S_IFLNK == (pMode & fuse.S_IFDIR)
119+
default:
120+
return false
95121
}
96122
}
97123

@@ -104,4 +130,4 @@ func genQueryID(path string, md fs.Metadata) (cid.Cid) {
104130
prefix := cid.V1Builder{Codec: cid.DagCBOR, MhType: multihash.BLAKE2B_MIN}
105131
return prefix.Sum(append([]byte(path), mdBuf...))
106132
}
107-
*/
133+
*/

filesystem/node/soft/pinRoot.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package fsnode
33
import (
44
"context"
55
"time"
6+
67
//TODO: consider /ipfs/interface-go-ipfs-filesystem/node ?
78
coreiface "github.com/ipfs/interface-go-ipfs-core"
89
fs "github.com/ipfs/interface-go-ipfs-core/filesystem/interface"
@@ -14,26 +15,31 @@ type pinRoot struct {
1415
pinAPI coreiface.PinAPI
1516
}
1617

17-
func (pr *pinRoot) YieldIo(ctx context.Context) (io interface{}, err error) {
18-
//TODO: some way to ping the pinapi or coreapi here
19-
return pr, nil
20-
}
21-
2218
func PinParser(pinAPI coreiface.PinAPI, epoch time.Time) fs.ParseFn {
2319
return func(_ context.Context, path string) (fs.Node, error) {
2420
if path != "" {
2521
return nil, fs.ErrInvalidPath
2622
}
27-
return &pinRoot{pinAPI: pinAPI, softDirRoot: csd(path, epoch)}, nil
23+
return &pinRoot{pinAPI: pinAPI, SoftDirRoot: csd(path, epoch)}, nil
2824
}
2925
}
3026

27+
func (pr *pinRoot) Version() uint {
28+
pr.version++ //TODO: we need a "has changed" signal from the pinservice to be cache friendly
29+
return pr.version
30+
}
31+
32+
func (pr *pinRoot) YieldIo(ctx context.Context) (io interface{}, err error) {
33+
//TODO: some way to ping the pinapi or coreapi here
34+
return pr, nil
35+
}
36+
3137
func (pr *pinRoot) Read(ctx context.Context, offset int64) <-chan string {
3238
pins, err := pr.pinAPI.Ls(ctx, coreoptions.Pin.Type.Recursive())
3339
if err != nil {
3440
return nil
3541
}
36-
return stringStream(ctx, pins)
42+
return pinMux(ctx, pins...)
3743
}
3844

3945
func (pr *pinRoot) Entries() int {

filesystem/node/soft/roots.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,29 +44,10 @@ func (sd *SoftDirRoot) InitMetadata(ctx context.Context) (*fuse.Stat_t, error) {
4444
return nodeStat, nil
4545
}
4646

47-
48-
func (sd *SoftDirRoot) Create(ctx context.Context, nodeType fs.Kind) error {
49-
return fs.ErrIOType
50-
}
51-
5247
func (mr *mountRoot) YieldIo(ctx context.Context) (io interface{}, err error) {
5348
return mr, nil
5449
}
5550

56-
func stringStream(ctx context.Context, strings...string) <-chan string {
57-
stringChan := make(chan string)
58-
go func (){
59-
for _, s := range strings {
60-
select {
61-
case ctx.Done():return
62-
case stringChan <-s:
63-
}
64-
}
65-
close(stringChan)
66-
}()
67-
return stringChan
68-
}
69-
7051
func (mr *mountRoot) Read(ctx context.Context, offset int64) <-chan string {
7152
return stringStream(ctx, mr.subroots)
7253
}

filesystem/node/soft/utils.go

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
package fsnode
22

3-
func csd(path string, now fuse.Timespec) softDirRoot {
3+
import (
4+
"context"
5+
"time"
6+
7+
"github.com/billziss-gh/cgofuse/fuse"
8+
)
9+
10+
func csd(path string, metaTimes time.Time) softDirRoot {
411
sd := softDirRoot{recordBase: crb(path)}
12+
now := fuse.NewTimespec(metaTimes)
513
meta := &sd.recordBase.metadata
614
meta.Birthtim, meta.Mtim, meta.Ctim = now, now, now // !!!
715
meta.Atim = fuse.Now()
@@ -10,4 +18,34 @@ func csd(path string, now fuse.Timespec) softDirRoot {
1018

1119
func crb(path string) fsnode.BaseNode {
1220
return fsnode.BaseNode{path: path, ioHandles: make(nodeHandles)}
13-
}
21+
}
22+
23+
func stringStream(ctx context.Context, strings ...string) <-chan string {
24+
stringChan := make(chan string)
25+
go func() {
26+
for _, s := range strings {
27+
select {
28+
case ctx.Done():
29+
return
30+
case stringChan <- s:
31+
}
32+
}
33+
close(stringChan)
34+
}()
35+
return stringChan
36+
}
37+
38+
func pinMux(ctx context.Context, pins ...coreiface.Pin) <-chan string {
39+
pinChan := make(chan string)
40+
go func() {
41+
for _, pin := range pins {
42+
select {
43+
case ctx.Done():
44+
return
45+
case pinChan <- pin.String():
46+
}
47+
}
48+
close(pinChan)
49+
}()
50+
return pinChan
51+
}

0 commit comments

Comments
 (0)