Skip to content
This repository has been archived by the owner on Feb 3, 2018. It is now read-only.

Commit

Permalink
Ensure writing deptree works for bzr, hg
Browse files Browse the repository at this point in the history
The main fix here is avoiding creating an empty directory for the
destination, as copyDir() doesn't like that. Instead, we create only
up to the parent dir.

The other bit is ensuring the source repos exist in the cache before
attempting to export them, for both bzr and hg.

Addresses golang/dep#144
  • Loading branch information
sdboyer committed Jan 26, 2017
1 parent 4284958 commit 6fd33b5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
7 changes: 4 additions & 3 deletions result.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package gps
import (
"fmt"
"os"
"path"
"path/filepath"
)

Expand Down Expand Up @@ -46,9 +45,11 @@ func WriteDepTree(basedir string, l Lock, sm SourceManager, sv bool) error {

// TODO(sdboyer) parallelize
for _, p := range l.Projects() {
to := path.Join(basedir, string(p.Ident().ProjectRoot))
to := filepath.FromSlash(filepath.Join(basedir, string(p.Ident().ProjectRoot)))

err := os.MkdirAll(to, 0777)
// Only make the parent dir, as some source implementations will balk on
// trying to write to an empty but existing dir.
err := os.MkdirAll(filepath.Dir(to), 0777)
if err != nil {
return err
}
Expand Down
42 changes: 36 additions & 6 deletions result_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package gps

import (
"io/ioutil"
"os"
"path"
"path/filepath"
"testing"
)

Expand Down Expand Up @@ -43,26 +45,54 @@ func TestWriteDepTree(t *testing.T) {
t.Skip("Skipping dep tree writing test in short mode")
}

r := basicResult
tmp, err := ioutil.TempDir("", "writetree")
if err != nil {
t.Errorf("Failed to create temp dir: %s", err)
t.FailNow()
}
defer os.RemoveAll(tmp)

tmp := path.Join(os.TempDir(), "vsolvtest")
os.RemoveAll(tmp)
r := solution{
att: 1,
p: []LockedProject{
pa2lp(atom{
id: pi("github.com/sdboyer/testrepo"),
v: NewBranch("master").Is(Revision("4d59fb584b15a94d7401e356d2875c472d76ef45")),
}, nil),
pa2lp(atom{
id: pi("launchpad.net/govcstestbzrrepo"),
v: NewVersion("1.0.0").Is(Revision("[email protected]")),
}, nil),
pa2lp(atom{
id: pi("bitbucket.org/sdboyer/withbm"),
v: NewVersion("v1.0.0").Is(Revision("aa110802a0c64195d0a6c375c9f66668827c90b4")),
}, nil),
},
}

sm, clean := mkNaiveSM(t)
defer clean()

// nil lock/result should err immediately
err := WriteDepTree(path.Join(tmp, "export"), nil, sm, true)
err = WriteDepTree(tmp, nil, sm, true)
if err == nil {
t.Errorf("Should error if nil lock is passed to WriteDepTree")
}

err = WriteDepTree(path.Join(tmp, "export"), r, sm, true)
err = WriteDepTree(tmp, r, sm, true)
if err != nil {
t.Errorf("Unexpected error while creating vendor tree: %s", err)
}

// TODO(sdboyer) add more checks
if _, err = os.Stat(filepath.Join(tmp, "github.com", "sdboyer", "testrepo")); err != nil {
t.Errorf("Directory for github.com/sdboyer/testrepo does not exist")
}
if _, err = os.Stat(filepath.Join(tmp, "launchpad.net", "govcstestbzrrepo")); err != nil {
t.Errorf("Directory for launchpad.net/govcstestbzrrepo does not exist")
}
if _, err = os.Stat(filepath.Join(tmp, "bitbucket.org", "sdboyer", "withbm")); err != nil {
t.Errorf("Directory for bitbucket.org/sdboyer/withbm does not exist")
}
}

func BenchmarkCreateVendorTree(b *testing.B) {
Expand Down
3 changes: 3 additions & 0 deletions source.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,5 +432,8 @@ func (bs *baseVCSSource) toRevOrErr(v Version) (r Revision, err error) {
}

func (bs *baseVCSSource) exportVersionTo(v Version, to string) error {
if err := bs.ensureCacheExistence(); err != nil {
return err
}
return bs.crepo.exportVersionTo(v, to)
}

0 comments on commit 6fd33b5

Please sign in to comment.