Skip to content

Commit

Permalink
fix checks on manifest path ('currentInput') for command 'pack'
Browse files Browse the repository at this point in the history
  • Loading branch information
sduchesneau committed Sep 22, 2023
1 parent f145281 commit d050e33
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cmd/substreams/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func runPack(cmd *cobra.Command, args []string) error {
}

if !manifestReader.IsLocalManifest() {
return fmt.Errorf(`"pack" can only be use to pack local manifest file`)
return fmt.Errorf(`"pack" can only be used to pack local manifest file`)
}

pkg, err := manifestReader.Read()
Expand Down
32 changes: 16 additions & 16 deletions manifest/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ import (
"bytes"
"context"
"fmt"
ipfs "github.com/ipfs/go-ipfs-api"
"github.com/jhump/protoreflect/dynamic"
"github.com/streamingfast/dstore"
"golang.org/x/mod/semver"
"google.golang.org/protobuf/proto"
"io"
"net/http"
"net/url"
Expand All @@ -18,6 +13,12 @@ import (
"strings"
"time"

ipfs "github.com/ipfs/go-ipfs-api"
"github.com/jhump/protoreflect/dynamic"
"github.com/streamingfast/dstore"
"golang.org/x/mod/semver"
"google.golang.org/protobuf/proto"

"github.com/jhump/protoreflect/desc"
"github.com/streamingfast/cli"
pbsubstreams "github.com/streamingfast/substreams/pb/sf/substreams/v1"
Expand Down Expand Up @@ -120,6 +121,10 @@ func newReader(input, workingDir string, opts ...Option) (*Reader, error) {
workingDir: workingDir,
}

if err := r.resolveInputPath(); err != nil {
return nil, err
}

for _, opt := range opts {
opt(r)
}
Expand All @@ -141,10 +146,6 @@ func (r *Reader) MustRead() *pbsubstreams.Package {
}

func (r *Reader) read() error {
if r.currentInput == "" {
r.currentInput = r.originalInput
}

input := r.currentInput
if r.IsRemotePackage(input) {
return r.readRemote(input)
Expand Down Expand Up @@ -265,10 +266,6 @@ func (r *Reader) readFromIPFS(input string) error {
}

func (r *Reader) readLocal(input string) error {
err := r.resolveInputPath(input)
if err != nil {
return fmt.Errorf("unable to resolve input path %q: %w", input, err)
}
input = r.currentInput

b, err := os.ReadFile(input)
Expand All @@ -280,7 +277,8 @@ func (r *Reader) readLocal(input string) error {
return nil
}

func (r *Reader) resolveInputPath(input string) error {
func (r *Reader) resolveInputPath() error {
input := r.originalInput
if r.IsRemotePackage(input) {
r.currentInput = input
return nil
Expand All @@ -301,6 +299,8 @@ func (r *Reader) resolveInputPath(input string) error {
return nil
}

r.currentInput = input

return nil
}

Expand Down Expand Up @@ -515,13 +515,13 @@ func (r *Reader) IsRemotePackage(input string) bool {
}

// IsLocalManifest determines if reader's input to read the manifest is a local manifest file, which is determined
// by ensure it's not a remote package and if the file end with `.yaml`.
// by ensure it's not a remote package and if the file end with `.yaml` or `.yml`.
func (r *Reader) IsLocalManifest() bool {
if r.IsRemotePackage(r.currentInput) {
return false
}

return strings.HasSuffix(r.currentInput, ".yaml")
return strings.HasSuffix(r.currentInput, ".yaml") || strings.HasSuffix(r.currentInput, ".yml")
}

// IsLikelyManifestInput determines if the input is likely a manifest input, which is determined
Expand Down

0 comments on commit d050e33

Please sign in to comment.