From 6fd33b58854b7ea941143965886047b6ba852b9c Mon Sep 17 00:00:00 2001 From: sam boyer Date: Thu, 26 Jan 2017 00:23:43 -0500 Subject: [PATCH 1/3] Ensure writing deptree works for bzr, hg 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 --- result.go | 7 ++++--- result_test.go | 42 ++++++++++++++++++++++++++++++++++++------ source.go | 3 +++ 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/result.go b/result.go index e38f08d..d46b6a6 100644 --- a/result.go +++ b/result.go @@ -3,7 +3,6 @@ package gps import ( "fmt" "os" - "path" "path/filepath" ) @@ -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 } diff --git a/result_test.go b/result_test.go index d0fd972..ee6ab35 100644 --- a/result_test.go +++ b/result_test.go @@ -1,8 +1,10 @@ package gps import ( + "io/ioutil" "os" "path" + "path/filepath" "testing" ) @@ -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("matt@mattfarina.com-20150731135137-pbphasfppmygpl68")), + }, 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) { diff --git a/source.go b/source.go index 66636f4..18fb667 100644 --- a/source.go +++ b/source.go @@ -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) } From 02e3f3aef2da420428541f635d5a770ff737b880 Mon Sep 17 00:00:00 2001 From: sam boyer Date: Thu, 26 Jan 2017 08:42:32 -0500 Subject: [PATCH 2/3] Maybe it wants the parent now? ugh --- result.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/result.go b/result.go index d46b6a6..c2098e3 100644 --- a/result.go +++ b/result.go @@ -49,7 +49,8 @@ func WriteDepTree(basedir string, l Lock, sm SourceManager, sv bool) error { // 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) + //err := os.MkdirAll(filepath.Dir(to), 0777) + err := os.MkdirAll(to, 0777) if err != nil { return err } From 6ea21bd63601abf4e727e05ce22601a609f5a628 Mon Sep 17 00:00:00 2001 From: sam boyer Date: Thu, 26 Jan 2017 10:22:48 -0500 Subject: [PATCH 3/3] Separate mkdir logic per the needs of the source --- result.go | 8 -------- source.go | 9 +++++++++ vcs_source.go | 4 ++++ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/result.go b/result.go index c2098e3..14200ab 100644 --- a/result.go +++ b/result.go @@ -47,14 +47,6 @@ func WriteDepTree(basedir string, l Lock, sm SourceManager, sv bool) error { for _, p := range l.Projects() { to := filepath.FromSlash(filepath.Join(basedir, string(p.Ident().ProjectRoot))) - // 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) - err := os.MkdirAll(to, 0777) - if err != nil { - return err - } - err = sm.ExportProject(p.Ident(), p.Version(), to) if err != nil { removeAll(basedir) diff --git a/source.go b/source.go index 18fb667..2ee2ec5 100644 --- a/source.go +++ b/source.go @@ -2,6 +2,8 @@ package gps import ( "fmt" + "os" + "path/filepath" "sync" ) @@ -435,5 +437,12 @@ func (bs *baseVCSSource) exportVersionTo(v Version, to string) error { if err := bs.ensureCacheExistence(); err != nil { return err } + + // Only make the parent dir, as the general implementation will balk on + // trying to write to an empty but existing dir. + if err := os.MkdirAll(filepath.Dir(to), 0777); err != nil { + return err + } + return bs.crepo.exportVersionTo(v, to) } diff --git a/vcs_source.go b/vcs_source.go index 194a74e..3663a97 100644 --- a/vcs_source.go +++ b/vcs_source.go @@ -40,6 +40,10 @@ func (s *gitSource) exportVersionTo(v Version, to string) error { return err } + if err := os.MkdirAll(to, 0777); err != nil { + return err + } + do := func() error { s.crepo.mut.Lock() defer s.crepo.mut.Unlock()