MCPcopy Create free account
hub / github.com/XTXMarkets/ternfs / Resolve

Method Resolve

go/terncli/filesamples/filesamples.go:47–82  ·  view source on GitHub ↗
(ownerInode msgs.InodeId, filename string)

Source from the content-addressed store, hash-verified

45}
46
47func (r *resolver) Resolve(ownerInode msgs.InodeId, filename string) (string, error) {
48 filepath := filename
49 currentDir := ownerInode
50 for {
51 // Get the next owner inode.
52 statReq := msgs.StatDirectoryReq{
53 Id: currentDir,
54 }
55 statResp := msgs.StatDirectoryResp{}
56 if err := r.ternClient.ShardRequest(r.logger, currentDir.Shard(), &statReq, &statResp); err != nil {
57 return "", fmt.Errorf("StatDirectoryReq to shard %v for inode %v failed: %w", currentDir.Shard(), currentDir, err)
58 }
59 owner := statResp.Owner
60 // If we're at the top level, then we're done.
61 if currentDir == msgs.ROOT_DIR_INODE_ID {
62 return path.Join("/", filepath), nil
63 }
64 // If we've found a null inode ID, then we won't be able to chase things any further.
65 if owner == msgs.NULL_INODE_ID {
66 return filepath, nil
67 }
68 // Get the name of the next node locally if possible.
69 if dirName, exists := r.getDirName(currentDir); exists {
70 filepath = path.Join(dirName, filepath)
71 currentDir = owner
72 continue
73 }
74 dirName, err := r.getNameFromShard(owner, currentDir)
75 if err != nil {
76 return "", fmt.Errorf("failed to lookup directory name from shard: %w", err)
77 }
78 r.setDirName(currentDir, dirName)
79 filepath = path.Join(dirName, filepath)
80 currentDir = owner
81 }
82}
83
84func (r *resolver) ResolveFilePaths(input io.Reader, output io.Writer) {
85 reader := csv.NewReader(input)

Callers 1

ResolveFilePathsMethod · 0.95

Calls 5

getDirNameMethod · 0.95
getNameFromShardMethod · 0.95
setDirNameMethod · 0.95
ShardRequestMethod · 0.80
ShardMethod · 0.45

Tested by

no test coverage detected