1 Star 0 Fork 0

goproxies/github.com-kardianos-govendor

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
old.go 2.45 KB
一键复制 编辑 原始数据 按行查看 历史
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package migrate
import (
"os"
"path/filepath"
"github.com/kardianos/govendor/context"
)
func init() {
register("internal", sysInternal{})
register("old-vendor", sysOldVendor{})
}
type sysInternal struct{}
func (sys sysInternal) Check(root string) (system, error) {
vendorFolder := "internal"
override := os.Getenv("GOVENDORFOLDER")
if len(override) != 0 {
vendorFolder = override
}
if hasDirs(root, vendorFolder) && hasFiles(root, filepath.Join(vendorFolder, "vendor.json")) {
return sys, nil
}
return nil, nil
}
func (sysInternal) Migrate(root string) error {
// Un-rewrite import paths.
// Copy files from internal to vendor.
// Update and move vendor file from "internal/vendor.json" to "vendor.json".
ctx, err := context.NewContext(root, filepath.Join("internal", "vendor.json"), "internal", true)
if err != nil {
return err
}
list, err := ctx.Status()
if err != nil {
return err
}
remove := make([]string, 0, len(list))
for _, item := range list {
if item.Status.Location != context.LocationVendor {
continue
}
pkg := ctx.Package[item.Local]
ctx.Operation = append(ctx.Operation, &context.Operation{
Pkg: pkg,
Src: pkg.Dir,
Dest: filepath.Join(ctx.RootDir, "vendor", filepath.ToSlash(item.Pkg.Path)),
})
remove = append(remove, filepath.Join(ctx.RootGopath, filepath.ToSlash(item.Local)))
ctx.RewriteRule[item.Local] = item.Pkg.Path
}
ctx.VendorFilePath = filepath.Join(ctx.RootDir, "vendor", "vendor.json")
err = ctx.WriteVendorFile()
if err != nil {
return err
}
err = ctx.Alter()
if err != nil {
return err
}
// Remove existing.
for _, r := range remove {
err = context.RemovePackage(r, "", false)
if err != nil {
return err
}
}
return os.Remove(filepath.Join(ctx.RootDir, "internal", "vendor.json"))
}
type sysOldVendor struct{}
func (sys sysOldVendor) Check(root string) (system, error) {
if hasDirs(root, "vendor") && hasFiles(root, "vendor.json") {
return sys, nil
}
return nil, nil
}
func (sysOldVendor) Migrate(root string) error {
ctx, err := context.NewContext(root, "vendor.json", "vendor", false)
if err != nil {
return err
}
ctx.VendorFilePath = filepath.Join(ctx.RootDir, "vendor", "vendor.json")
err = ctx.WriteVendorFile()
if err != nil {
return err
}
return os.Remove(filepath.Join(ctx.RootDir, "vendor.json"))
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/goproxies/github.com-kardianos-govendor.git
git@gitee.com:goproxies/github.com-kardianos-govendor.git
goproxies
github.com-kardianos-govendor
github.com-kardianos-govendor
v1.0.9

搜索帮助