예제 #1
0
파일: restore.go 프로젝트: arya/gvt
func downloadDependency(dep vendor.Dependency) error {
	log.Printf("fetching %s", dep.Importpath)
	repo, _, err := vendor.DeduceRemoteRepo(dep.Importpath, rbInsecure)
	if err != nil {
		return fmt.Errorf("dependency could not be processed: %s", err)
	}
	wc, err := repo.Checkout("", "", dep.Revision)
	if err != nil {
		return fmt.Errorf("dependency could not be fetched: %s", err)
	}
	dst := filepath.Join(vendorDir(), dep.Importpath)
	src := filepath.Join(wc.Dir(), dep.Path)

	if _, err := os.Stat(dst); err == nil {
		if err := fileutils.RemoveAll(dst); err != nil {
			return fmt.Errorf("dependency could not be deleted: %v", err)
		}
	}

	if err := fileutils.Copypath(dst, src); err != nil {
		return err
	}

	if err := wc.Destroy(); err != nil {
		return err
	}

	return nil
}
예제 #2
0
파일: restore.go 프로젝트: elithrar/gvt
func downloadDependency(dep vendor.Dependency) error {
	log.Printf("fetching %s", dep.Importpath)
	repo, _, err := vendor.DeduceRemoteRepo(dep.Importpath, rbInsecure)
	if err != nil {
		return fmt.Errorf("dependency could not be processed: %s", err)
	}
	// We can't pass the branch here, and benefit from narrow clones, as the
	// revision might not be in the branch tree anymore. Thanks rebase.
	wc, err := repo.Checkout("", "", dep.Revision)
	if err != nil {
		return fmt.Errorf("dependency could not be fetched: %s", err)
	}
	dst := filepath.Join(vendorDir(), dep.Importpath)
	src := filepath.Join(wc.Dir(), dep.Path)

	if _, err := os.Stat(dst); err == nil {
		if err := fileutils.RemoveAll(dst); err != nil {
			return fmt.Errorf("dependency could not be deleted: %v", err)
		}
	}

	if err := fileutils.Copypath(dst, src); err != nil {
		return err
	}

	if err := wc.Destroy(); err != nil {
		return err
	}

	return nil
}
예제 #3
0
파일: restore.go 프로젝트: torfuzx/gb
func restore(ctx *gb.Context) error {
	m, err := vendor.ReadManifest(manifestFile(ctx))
	if err != nil {
		return fmt.Errorf("could not load manifest: %v", err)
	}

	for _, dep := range m.Dependencies {
		fmt.Printf("Getting %s\n", dep.Importpath)
		repo, _, err := vendor.DeduceRemoteRepo(dep.Importpath, insecure)
		if err != nil {
			return fmt.Errorf("Could not process dependency: %s", err)
		}
		wc, err := repo.Checkout("", "", dep.Revision)
		if err != nil {
			return fmt.Errorf("Could not retrieve dependency: %s", err)
		}
		dst := filepath.Join(ctx.Projectdir(), "vendor", "src", dep.Importpath)
		src := filepath.Join(wc.Dir(), dep.Path)

		if err := fileutils.Copypath(dst, src); err != nil {
			return err
		}

		if err := wc.Destroy(); err != nil {
			return err
		}

	}
	return nil
}
예제 #4
0
파일: restore.go 프로젝트: jzt/gvt
func downloadDependency(dep vendor.Dependency, vendorDir string, recursive bool) error {
	if recursive {
		log.Printf("fetching recursive %s", dep.Importpath)
	} else {
		log.Printf("fetching %s", dep.Importpath)
	}

	repo, _, err := vendor.DeduceRemoteRepo(dep.Importpath, rbInsecure)
	if err != nil {
		return fmt.Errorf("dependency could not be processed: %s", err)
	}
	// We can't pass the branch here, and benefit from narrow clones, as the
	// revision might not be in the branch tree anymore. Thanks rebase.
	wc, err := repo.Checkout("", "", dep.Revision)
	if err != nil {
		return fmt.Errorf("dependency could not be fetched: %s", err)
	}
	dst := filepath.Join(vendorDir, dep.Importpath)
	src := filepath.Join(wc.Dir(), dep.Path)

	if _, err := os.Stat(dst); err == nil {
		if err := fileutils.RemoveAll(dst); err != nil {
			return fmt.Errorf("dependency could not be deleted: %v", err)
		}
	}

	if err := fileutils.Copypath(dst, src); err != nil {
		return err
	}

	if err := wc.Destroy(); err != nil {
		return err
	}

	// Check for for manifests in dependencies
	man := filepath.Join(dst, "vendor", "manifest")
	venDir := filepath.Join(dst, "vendor")
	if _, err := os.Stat(man); err == nil {
		m, err := vendor.ReadManifest(man)
		if err != nil {
			return fmt.Errorf("could not load manifest: %v", err)
		}
		var errors uint32
		for _, d := range m.Dependencies {
			if err := downloadDependency(d, venDir, true); err != nil {
				log.Printf("%s: %v", d.Importpath, err)
				atomic.AddUint32(&errors, 1)
			}
		}
	}

	return nil
}
예제 #5
0
파일: fetch.go 프로젝트: elithrar/gvt
func fetch(path string, recurse bool) error {
	m, err := vendor.ReadManifest(manifestFile())
	if err != nil {
		return fmt.Errorf("could not load manifest: %v", err)
	}

	repo, extra, err := vendor.DeduceRemoteRepo(path, insecure)
	if err != nil {
		return err
	}

	// strip of any scheme portion from the path, it is already
	// encoded in the repo.
	path = stripscheme(path)

	if m.HasImportpath(path) {
		return fmt.Errorf("%s is already vendored", path)
	}

	wc, err := repo.Checkout(branch, tag, revision)

	if err != nil {
		return err
	}

	rev, err := wc.Revision()
	if err != nil {
		return err
	}

	branch, err := wc.Branch()
	if err != nil {
		return err
	}

	dep := vendor.Dependency{
		Importpath: path,
		Repository: repo.URL(),
		Revision:   rev,
		Branch:     branch,
		Path:       extra,
	}

	if err := m.AddDependency(dep); err != nil {
		return err
	}

	dst := filepath.Join(vendorDir(), dep.Importpath)
	src := filepath.Join(wc.Dir(), dep.Path)

	if err := fileutils.Copypath(dst, src); err != nil {
		return err
	}

	if err := vendor.WriteManifest(manifestFile(), m); err != nil {
		return err
	}

	if err := wc.Destroy(); err != nil {
		return err
	}

	if !recurse {
		return nil
	}

	// if we are recursing, overwrite branch, tag and revision
	// values so recursive fetching checks out from HEAD.
	branch = ""
	tag = ""
	revision = ""

	for done := false; !done; {

		paths := []struct {
			Root, Prefix string
		}{
			{filepath.Join(runtime.GOROOT(), "src"), ""},
		}
		m, err := vendor.ReadManifest(manifestFile())
		if err != nil {
			return err
		}
		for _, d := range m.Dependencies {
			paths = append(paths, struct{ Root, Prefix string }{filepath.Join(vendorDir(), filepath.FromSlash(d.Importpath)), filepath.FromSlash(d.Importpath)})
		}

		dsm, err := vendor.LoadPaths(paths...)
		if err != nil {
			return err
		}

		is, ok := dsm[filepath.Join(vendorDir(), path)]
		if !ok {
			return fmt.Errorf("unable to locate depset for %q", path)
		}

		missing := findMissing(pkgs(is.Pkgs), dsm)
		switch len(missing) {
		case 0:
			done = true
		default:

			// sort keys in ascending order, so the shortest missing import path
			// with be fetched first.
			keys := keys(missing)
			sort.Strings(keys)
			pkg := keys[0]
			log.Printf("fetching recursive dependency %s", pkg)
			if err := fetch(pkg, false); err != nil {
				return err
			}
		}
	}

	return nil
}
예제 #6
0
파일: update.go 프로젝트: sekimura/gvt
				Importpath: d.Importpath,
				Repository: repo.URL(),
				Revision:   rev,
				Branch:     branch,
				Path:       extra,
			}

			if err := fileutils.RemoveAll(filepath.Join(vendorDir(), filepath.FromSlash(d.Importpath))); err != nil {
				// TODO(dfc) need to apply vendor.cleanpath here to remove intermediate directories.
				return fmt.Errorf("dependency could not be deleted: %v", err)
			}

			dst := filepath.Join(vendorDir(), filepath.FromSlash(dep.Importpath))
			src := filepath.Join(wc.Dir(), dep.Path)

			if err := fileutils.Copypath(dst, src); err != nil {
				return err
			}

			if err := m.AddDependency(dep); err != nil {
				return err
			}

			if err := vendor.WriteManifest(manifestFile(), m); err != nil {
				return err
			}

			if err := wc.Destroy(); err != nil {
				return err
			}
		}