Skip to content
This repository has been archived by the owner on Aug 22, 2022. It is now read-only.

pkger -include fails when using modules versioned with tags + path #143

Open
ideasculptor opened this issue Feb 4, 2021 · 0 comments
Open

Comments

@ideasculptor
Copy link

If you are using go modules with versions specified via path and tag, pkger -include fails.

go.mod:

module github.com/thisisme/somerepo/v10

go 1.14

require (
        ...
	github.com/markbates/pkger v0.17.1
	github.com/thisisme/soimeotherrepo/v2 v2.0.2
        ...
)

some/nested/path/main.go:

package main

import (
	"fmt"
	"io"
	"os"

	"github.com/tunein/go-logging/v3"

	"github.com/markbates/pkger"
)

func main() {
	f, err := pkger.Open("/some/nested/path/file.txt")
	if err != nil {
		logging.Error(err, "error opening file")
		os.Exit(-1)
	}
	defer f.Close()

	info, err := f.Stat()
	if err != nil {
		logging.Error(err, "error stating file")
		os.Exit(-1)
	}

	fmt.Println("Name: ", info.Name())
	fmt.Println("Size: ", info.Size())
	fmt.Println("Mode: ", info.Mode())
	fmt.Println("ModTime: ", info.ModTime())

	if _, err := io.Copy(os.Stdout, f); err != nil {
		logging.Error(err, "error copying file to stdout")
		os.Exit(-1)
	}
	os.Exit(0)
}

some/nested/path/file.txt:

this is some text
and this is some more

I can run pkger -o some/nested/path and everything works just fine, generating some/nested/path/pkged.go with package main. However, if I run pkger -include /some/nested/path -o some/nested/path, I get errors because it doesn't correctly resolve that the /v10 suffix on the module declared in the go.mod file is the current directory, so it tries to go to github to get it.

2021/02/04 15:06:08 exit status 1: go: finding module for package github.com/thisisme/somerepo/v10
can't load package: package github.com/thisisme/somerepo/v10: module github.com/thisisme/somerepo@latest found (v7.0.23+incompatible), but does not contain package github.com/thisisme/somerepo/v10

From version 8, we have been explicitly declaring the module with the path element containing the major version, so the most recent version it can find without a /vN suffix is v7.0.23, which is tagged, but still uses the bare name for the module declaration. Since this module has a lot of directories and many files, running pkger without -include in order to include a single text file takes a remarkably long time. It's not the end of the world, but it would be better if it worked correctly with path-based go module versioning.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant