Skip to content

Commit

Permalink
ipfs: meta from core API instead of node directly
Browse files Browse the repository at this point in the history
Specifically this fixes handling of CIDv1/raw nodes when fetching
their size.
  • Loading branch information
djdv committed Jan 4, 2023
1 parent 8afdf17 commit 957f536
Showing 1 changed file with 9 additions and 32 deletions.
41 changes: 9 additions & 32 deletions internal/filesystem/ipfs/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package ipfs
import (
"bytes"
"context"
"errors"
"fmt"
"io"
"io/fs"
Expand All @@ -15,9 +14,6 @@ import (
files "github.com/ipfs/go-ipfs-files"
cbor "github.com/ipfs/go-ipld-cbor"
ipld "github.com/ipfs/go-ipld-format" // TODO: migrate to new standard
dag "github.com/ipfs/go-merkledag"
"github.com/ipfs/go-unixfs"
unixpb "github.com/ipfs/go-unixfs/pb"
coreiface "github.com/ipfs/interface-go-ipfs-core"
corepath "github.com/ipfs/interface-go-ipfs-core/path"
)
Expand Down Expand Up @@ -410,15 +406,6 @@ func openIPFSFile(name string, core coreiface.CoreAPI, ipldNode ipld.Node,

func openUFSNode(name string, core coreiface.CoreAPI, ipldNode ipld.Node,
) (fs.File, error) {
typedNode, ok := ipldNode.(*dag.ProtoNode)
if !ok {
return nil, errors.New("TODO")
}
ufsNode, err := unixfs.ExtractFSNode(typedNode)
if err != nil {
return nil, err
}

var (
ufsPath = corepath.IpfsPath(ipldNode.Cid())
ctx, cancel = context.WithCancel(context.Background())
Expand All @@ -428,7 +415,6 @@ func openUFSNode(name string, core coreiface.CoreAPI, ipldNode ipld.Node,
cancel()
return nil, err
}

fileNode, ok := apiNode.(files.File)
if !ok {
cancel()
Expand All @@ -443,29 +429,20 @@ func openUFSNode(name string, core coreiface.CoreAPI, ipldNode ipld.Node,
),
)
}
size, err := fileNode.Size()
if err != nil {
cancel()
return nil, fserrors.New(fserrors.IO)
}

// TODO: store/get permissions from root.
const permissions = readAll | executeAll
// TODO: store permissions on the type and do this in the method for Mode()
mode := func() fs.FileMode {
mode := permissions
switch ufsNode.Type() {
case unixpb.Data_Directory, unixpb.Data_HAMTShard:
mode |= fs.ModeDir
case unixpb.Data_Symlink:
mode |= fs.ModeSymlink
case unixpb.Data_File, unixpb.Data_Raw:
// NOOP: mode |= fs.FileMode(0)
default:
mode |= fs.ModeIrregular
}
return mode
}()
return &coreFile{
stat: &coreFileInfo{
name: name,
size: int64(ufsNode.FileSize()),
// mode: unixfsTypeToGoType(ufsNode.Type()) | permissions,
mode: mode,
name: name,
size: size,
mode: permissions,
initTime: time.Now(), // TODO: from root
},
File: fileNode,
Expand Down

0 comments on commit 957f536

Please sign in to comment.