// Alter runs any requested package alterations.

Alter runs any requested package alterations.
// Alter runs any requested package alterations .
func (ctx *Context) Alter() error {
	ctx.added = nil
	buf := &bytes.Buffer{}
	for _, conflict := range ctx.Check() {
		buf.WriteString(fmt.Sprintf("Different Canonical Packages for %s\n", conflict.Canonical))
		for _, op := range conflict.Operation {
			buf.WriteString(fmt.Sprintf("\t%s\n", op.Pkg.Local))
		}
	}
	if buf.Len() != 0 {
		return errors.New(buf.String())
	}
	var err error
	fetch, err := newFetcher(ctx)
	if err != nil {
		return err
	}
	for {
		var nextOps []*Operation
		for _, op := range ctx.Operation {
			if op.State != OpReady {
				continue
			}
			switch op.Type {
			case OpFetch:
				var ops []*Operation
				ops, err = fetch.op(op)
				if len(ops) > 0 {
					nextOps = append(nextOps, ops...)
				}
			}
			if err != nil {
				return errors.Wrapf(err, "Failed to fetch package %q", op.Pkg.Path)
			}
		}
		if len(nextOps) == 0 {
			break
		}
		ctx.Operation = append(ctx.Operation, nextOps...)
	}
	for _, op := range ctx.Operation {
		if op.State != OpReady {
			continue
		}
		pkg := op.Pkg
		if pathos.FileStringEquals(op.Dest, op.Src) {
			panic("For package " + pkg.Local + " attempt to copy to same location: " + op.Src)
		}
		dprintf("MV: %s (%q -> %q)\n", pkg.Local, op.Src, op.Dest)
		switch op.Type {
		default:
			panic("unknown operation type")
		case OpRemove:
			ctx.dirty = true
			err = RemovePackage(op.Src, filepath.Join(ctx.RootDir, ctx.VendorFolder), pkg.IncludeTree)
			op.State = OpDone
		case OpCopy:
			err = ctx.copyOperation(op, nil)
			if os.IsNotExist(errors.Cause(err)) {
				err = nil
			}
		}
		if err != nil {
			return errors.Wrapf(err, "Failed to %v package %q -> %q", op.Type, op.Src, op.Dest)
		}
	}
	if ctx.rewriteImports {
		return ctx.rewrite()
	}
	return nil
}
func ( ctx * Context ) Alter ( ) error { ctx . added = nil buf := & bytes . Buffer { } for _ , conflict := range ctx . Check ( ) { buf . WriteString ( fmt . Sprintf ( " \n " , conflict . Canonical ) ) for _ , op := range conflict . Operation { buf . WriteString ( fmt . Sprintf ( " \t \n " , op . Pkg . Local ) ) } } if buf . Len ( ) != 0 { return errors . New ( buf . String ( ) ) } var err error fetch , err := newFetcher ( ctx ) if err != nil { return err } for { var nextOps [ ] * Operation for _ , op := range ctx . Operation { if op . State != OpReady { continue } switch op . Type { case OpFetch : var ops [ ] * Operation ops , err = fetch . op ( op ) if len ( ops ) > 0 { nextOps = append ( nextOps , ops ... ) } } if err != nil { return errors . Wrapf ( err , " " , op . Pkg . Path ) } } if len ( nextOps ) == 0 { break } ctx . Operation = append ( ctx . Operation , nextOps ... ) } for _ , op := range ctx . Operation { if op . State != OpReady { continue } pkg := op . Pkg if pathos . FileStringEquals ( op . Dest , op . Src ) { panic ( " " + pkg . Local + " " + op . Src ) } dprintf ( " \n " , pkg . Local , op . Src , op . Dest ) switch op . Type { default : panic ( " " ) case OpRemove : ctx . dirty = true err = RemovePackage ( op . Src , filepath . Join ( ctx . RootDir , ctx . VendorFolder ) , pkg . IncludeTree ) op . State = OpDone case OpCopy : err = ctx . copyOperation ( op , nil ) if os . IsNotExist ( errors . Cause ( err ) ) { err = nil } } if err != nil { return errors . Wrapf ( err , " " , op . Type , op . Src , op . Dest ) } } if ctx . rewriteImports { return ctx . rewrite ( ) } return nil }
Alter runs any requested package alterations.
Alter runs any requested package alterations .
// Ensure there are no conflicts at this time.
 // Download packages, transform fetch op into a copy op.
 // Move and possibly rewrite packages.
 // Copy the package or remove.
 // Ignore packages that don't exist, like appengine.
