Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

add sourceCachePath helper func #754

Merged
merged 1 commit into from
Jun 14, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions internal/gps/maybe_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,19 @@ func (sf sourceFailures) Error() string {
return buf.String()
}

// sourceCachePath returns a url-sanitized source cache dir path.
func sourceCachePath(cacheDir, sourceURL string) string {
return filepath.Join(cacheDir, "sources", sanitizer.Replace(sourceURL))
}

type maybeGitSource struct {
url *url.URL
}

func (m maybeGitSource) try(ctx context.Context, cachedir string, c singleSourceCache, superv *supervisor) (source, sourceState, error) {
ustr := m.url.String()
path := filepath.Join(cachedir, "sources", sanitizer.Replace(ustr))

r, err := newCtxRepo(vcs.Git, ustr, path)
r, err := newCtxRepo(vcs.Git, ustr, sourceCachePath(cachedir, ustr))

if err != nil {
return nil, 0, unwrapVcsErr(err)
Expand Down Expand Up @@ -140,7 +144,7 @@ func (m maybeGopkginSource) try(ctx context.Context, cachedir string, c singleSo
// We don't actually need a fully consistent transform into the on-disk path
// - just something that's unique to the particular gopkg.in domain context.
// So, it's OK to just dumb-join the scheme with the path.
path := filepath.Join(cachedir, "sources", sanitizer.Replace(m.url.Scheme+"/"+m.opath))
path := sourceCachePath(cachedir, m.url.Scheme+"/"+m.opath)
ustr := m.url.String()
r, err := newCtxRepo(vcs.Git, ustr, path)

Expand Down Expand Up @@ -189,9 +193,8 @@ type maybeBzrSource struct {

func (m maybeBzrSource) try(ctx context.Context, cachedir string, c singleSourceCache, superv *supervisor) (source, sourceState, error) {
ustr := m.url.String()
path := filepath.Join(cachedir, "sources", sanitizer.Replace(ustr))

r, err := newCtxRepo(vcs.Bzr, ustr, path)
r, err := newCtxRepo(vcs.Bzr, ustr, sourceCachePath(cachedir, ustr))

if err != nil {
return nil, 0, unwrapVcsErr(err)
Expand Down Expand Up @@ -231,9 +234,8 @@ type maybeHgSource struct {

func (m maybeHgSource) try(ctx context.Context, cachedir string, c singleSourceCache, superv *supervisor) (source, sourceState, error) {
ustr := m.url.String()
path := filepath.Join(cachedir, "sources", sanitizer.Replace(ustr))

r, err := newCtxRepo(vcs.Hg, ustr, path)
r, err := newCtxRepo(vcs.Hg, ustr, sourceCachePath(cachedir, ustr))

if err != nil {
return nil, 0, unwrapVcsErr(err)
Expand Down