fix dir name in module dir removal

This commit is contained in:
Shawn Smith
2021-11-28 19:35:26 +09:00
parent a40e0b584b
commit fe76353299
2 changed files with 8 additions and 7 deletions

View File

@@ -22,8 +22,8 @@ func (n notFoundError) Error() string {
return fmt.Sprintf("%q not found in cache", n.repo)
}
func dirName(repo string) string {
return fmt.Sprintf("_repos/src/%s", strings.ToLower(repo))
func dirName(repo, ver string) string {
return fmt.Sprintf("_repos/src/%s@%s", strings.ToLower(repo), ver)
}
func getFromCache(db *badger.DB, repo string) (checksResp, error) {
@@ -99,13 +99,13 @@ func newChecksResp(db *badger.DB, repo string, forceRefresh bool) (checksResp, e
return checksResp{}, fmt.Errorf("could not download repo: %v", err)
}
checkResult, err := check.Run(dirName(repo + "@" + ver))
checkResult, err := check.Run(dirName(repo, ver))
if err != nil {
return checksResp{}, err
}
defer func() {
err := os.RemoveAll(dirName(repo))
err := os.RemoveAll(dirName(repo, ver))
if err != nil {
log.Println("ERROR: could not remove dir:", err)
}

View File

@@ -4,15 +4,16 @@ import "testing"
var dirNameTests = []struct {
url string
ver string
want string
}{
{"github.com/foo/bar", "_repos/src/github.com/foo/bar"},
{"github.com/foo/bar", "v0.1.0", "_repos/src/github.com/foo/bar@v0.1.0"},
}
func TestDirName(t *testing.T) {
for _, tt := range dirNameTests {
if got := dirName(tt.url); got != tt.want {
t.Errorf("dirName(%q) = %q, want %q", tt.url, got, tt.want)
if got := dirName(tt.url, tt.ver); got != tt.want {
t.Errorf("dirName(%q, %q) = %q, want %q", tt.url, tt.ver, got, tt.want)
}
}
}