Skip to content

Commit 3d3dedb

Browse files
committed
ipfs: ipfs+ipns - pass op string to helper funcs
1 parent 0fb73ff commit 3d3dedb

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

internal/filesystem/ipfs/ipfs.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func (fsys *IPFS) Stat(name string) (fs.FileInfo, error) {
172172
if name == filesystem.Root {
173173
return &fsys.info, nil
174174
}
175-
cid, err := fsys.toCID(name)
175+
cid, err := fsys.toCID(op, name)
176176
if err != nil {
177177
return nil, err
178178
}
@@ -183,8 +183,7 @@ func (fsys *IPFS) Stat(name string) (fs.FileInfo, error) {
183183
return info, nil
184184
}
185185

186-
func (fsys *IPFS) toCID(goPath string) (cid.Cid, error) {
187-
const op = "IPFS.toCID"
186+
func (fsys *IPFS) toCID(op, goPath string) (cid.Cid, error) {
188187
// NOTE: core.Resolve{Path,Node} is typically correct for this
189188
// but we're trying to avoid communicating with the node
190189
// as much as possible, and ResolveX is expensive when
@@ -314,7 +313,7 @@ func (fsys *IPFS) Open(name string) (fs.File, error) {
314313
if !fs.ValidPath(name) {
315314
return nil, fserrors.New(op, name, filesystem.ErrPath, fserrors.InvalidItem)
316315
}
317-
cid, err := fsys.toCID(name)
316+
cid, err := fsys.toCID(op, name)
318317
if err != nil {
319318
return nil, err
320319
}

internal/filesystem/ipfs/ipns.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,18 @@ func (fsys *IPNS) Close() error {
150150
}
151151

152152
func (fsys *IPNS) Stat(name string) (fs.FileInfo, error) {
153+
const op = "stat"
153154
if name == filesystem.Root {
154155
return &fsys.info, nil
155156
}
156-
cid, err := fsys.toCID(name)
157+
cid, err := fsys.toCID(op, name)
157158
if err != nil {
158159
return nil, err
159160
}
160161
return fs.Stat(fsys.ipfs, cid.String())
161162
}
162163

163-
func (fsys *IPNS) toCID(goPath string) (cid.Cid, error) {
164-
const op = "IPNS.toResolved"
164+
func (fsys *IPNS) toCID(op, goPath string) (cid.Cid, error) {
165165
var (
166166
names = strings.Split(goPath, "/")
167167
root = names[0]
@@ -243,7 +243,7 @@ func (fsys *IPNS) Open(name string) (fs.File, error) {
243243
if !fs.ValidPath(name) {
244244
return nil, fserrors.New(op, name, filesystem.ErrPath, fserrors.InvalidItem)
245245
}
246-
cid, err := fsys.toCID(name)
246+
cid, err := fsys.toCID(op, name)
247247
if err != nil {
248248
return nil, err
249249
}
@@ -256,7 +256,7 @@ func (fsys *IPNS) Open(name string) (fs.File, error) {
256256
file: file,
257257
}
258258
nFile.refreshFn = func() error {
259-
fetchedCID, err := fsys.toCID(name)
259+
fetchedCID, err := fsys.toCID(op, name)
260260
if err != nil {
261261
return err
262262
}

0 commit comments

Comments
 (0)