From 174485038c15643d3002c0f4773d74480daa8a77 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Tue, 3 Oct 2023 12:42:18 +0300 Subject: refactor(tvix/nar-bridge): inline assemblePathInfo This is only called once. Change-Id: I342443b8d04050929733fc84d5f36cd64060afe3 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9525 Reviewed-by: Connor Brewster Autosubmit: flokli Tested-by: BuildkiteCI --- tvix/nar-bridge/pkg/reader/reader.go | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'tvix') diff --git a/tvix/nar-bridge/pkg/reader/reader.go b/tvix/nar-bridge/pkg/reader/reader.go index ff9804934ff4..764766b621fb 100644 --- a/tvix/nar-bridge/pkg/reader/reader.go +++ b/tvix/nar-bridge/pkg/reader/reader.go @@ -97,20 +97,6 @@ func (r *Reader) Import( return nil } - // Assemble a PathInfo struct, the Node is populated later. - assemblePathInfo := func() *storev1pb.PathInfo { - return &storev1pb.PathInfo{ - Node: nil, - References: [][]byte{}, - Narinfo: &storev1pb.NARInfo{ - NarSize: uint64(r.hrSha256.BytesWritten()), - NarSha256: r.hrSha256.Sum(nil), - Signatures: []*storev1pb.NARInfo_Signature{}, - ReferenceNames: []string{}, - }, - } - } - getBasename := func(p string) string { // extract the basename. In case of "/", replace with empty string. basename := path.Base(p) @@ -151,9 +137,20 @@ func (r *Reader) Import( } - // Stack is empty. We now either have a regular or symlink root node, or we encountered at least one directory. - // assemble pathInfo with these and return. - pi := assemblePathInfo() + // Stack is empty. We now either have a regular or symlink root node, + // or we encountered at least one directory assemble pathInfo with these and + // return. + pi := &storev1pb.PathInfo{ + Node: nil, + References: [][]byte{}, + Narinfo: &storev1pb.NARInfo{ + NarSize: uint64(r.hrSha256.BytesWritten()), + NarSha256: r.hrSha256.Sum(nil), + Signatures: []*storev1pb.NARInfo_Signature{}, + ReferenceNames: []string{}, + }, + } + if rootFile != nil { pi.Node = &castorev1pb.Node{ Node: &castorev1pb.Node_File{ -- cgit 1.4.1