• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

cinode / go / 6922264175

19 Nov 2023 06:33PM UTC coverage: 95.297% (+4.4%) from 90.909%
6922264175

push

github

byo
Merge branch 'internal-refactor'

1269 of 1343 new or added lines in 38 files covered. (94.49%)

3 existing lines in 2 files now uncovered.

2999 of 3147 relevant lines covered (95.3%)

1.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.89
/pkg/cinodefs/node_unloaded.go
1
/*
2
Copyright © 2023 Bartłomiej Święcki (byo)
3

4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7

8
    http://www.apache.org/licenses/LICENSE-2.0
9

10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
*/
16

17
package cinodefs
18

19
import (
20
        "context"
21
        "fmt"
22

23
        "github.com/cinode/go/pkg/cinodefs/internal/protobuf"
24
)
25

26
type nodeUnloaded struct {
27
        ep *Entrypoint
28
}
29

NEW
30
func (c *nodeUnloaded) dirty() dirtyState {
×
NEW
31
        return dsClean
×
NEW
32
}
×
33

34
func (c *nodeUnloaded) flush(ctx context.Context, gc *graphContext) (node, *Entrypoint, error) {
1✔
35
        return c, c.ep, nil
1✔
36
}
1✔
37

38
func (c *nodeUnloaded) traverse(
39
        ctx context.Context,
40
        gc *graphContext,
41
        path []string,
42
        pathPosition int,
43
        linkDepth int,
44
        isWritable bool,
45
        opts traverseOptions,
46
        whenReached traverseGoalFunc,
47
) (
48
        node,
49
        dirtyState,
50
        error,
51
) {
1✔
52
        loaded, err := c.load(ctx, gc)
1✔
53
        if err != nil {
2✔
54
                return nil, 0, err
1✔
55
        }
1✔
56

57
        return loaded.traverse(
1✔
58
                ctx,
1✔
59
                gc,
1✔
60
                path,
1✔
61
                pathPosition,
1✔
62
                linkDepth,
1✔
63
                isWritable,
1✔
64
                opts,
1✔
65
                whenReached,
1✔
66
        )
1✔
67
}
68

69
func (c *nodeUnloaded) load(ctx context.Context, gc *graphContext) (node, error) {
1✔
70
        // Data is behind some entrypoint, try to load it
1✔
71
        if c.ep.IsLink() {
2✔
72
                return c.loadEntrypointLink(ctx, gc)
1✔
73
        }
1✔
74

75
        if c.ep.IsDir() {
2✔
76
                return c.loadEntrypointDir(ctx, gc)
1✔
77
        }
1✔
78

79
        return &nodeFile{ep: c.ep}, nil
1✔
80
}
81

82
func (c *nodeUnloaded) loadEntrypointLink(ctx context.Context, gc *graphContext) (node, error) {
1✔
83
        targetEP := &Entrypoint{}
1✔
84
        err := gc.readProtobufMessage(ctx, c.ep, &targetEP.ep)
1✔
85
        if err != nil {
2✔
86
                return nil, fmt.Errorf("%w: %w", ErrCantOpenLink, err)
1✔
87
        }
1✔
88

89
        err = expandEntrypointProto(targetEP)
1✔
90
        if err != nil {
2✔
91
                return nil, fmt.Errorf("%w: %w", ErrCantOpenLink, err)
1✔
92
        }
1✔
93

94
        return &nodeLink{
1✔
95
                ep:     c.ep,
1✔
96
                target: &nodeUnloaded{ep: targetEP},
1✔
97
                dState: dsClean,
1✔
98
        }, nil
1✔
99
}
100

101
func (c *nodeUnloaded) loadEntrypointDir(ctx context.Context, gc *graphContext) (node, error) {
1✔
102
        msg := &protobuf.Directory{}
1✔
103
        err := gc.readProtobufMessage(ctx, c.ep, msg)
1✔
104
        if err != nil {
2✔
105
                return nil, fmt.Errorf("%w: %w", ErrCantOpenDir, err)
1✔
106
        }
1✔
107

108
        dir := make(map[string]node, len(msg.Entries))
1✔
109

1✔
110
        for _, entry := range msg.Entries {
2✔
111
                if entry.Name == "" {
2✔
112
                        return nil, fmt.Errorf("%w: %w", ErrCantOpenDir, ErrEmptyName)
1✔
113
                }
1✔
114
                if _, exists := dir[entry.Name]; exists {
2✔
115
                        return nil, fmt.Errorf("%w: %s", ErrCantOpenDirDuplicateEntry, entry.Name)
1✔
116
                }
1✔
117

118
                ep, err := entrypointFromProtobuf(entry.Ep)
1✔
119
                if err != nil {
2✔
120
                        return nil, fmt.Errorf("%w: %w", ErrCantOpenDir, err)
1✔
121
                }
1✔
122

123
                dir[entry.Name] = &nodeUnloaded{ep: ep}
1✔
124
        }
125

126
        return &nodeDirectory{
1✔
127
                stored:  c.ep,
1✔
128
                entries: dir,
1✔
129
                dState:  dsClean,
1✔
130
        }, nil
1✔
131
}
132

133
func (c *nodeUnloaded) entrypoint() (*Entrypoint, error) {
1✔
134
        return c.ep, nil
1✔
135
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc