Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
dep: Make SafeWriter use status map for OnChanged
Browse files Browse the repository at this point in the history
If vendor was empty, nonexistent, or just missing a few targeted items,
the SafeWriter would miss them.
  • Loading branch information
sdboyer committed Jul 21, 2018
1 parent 2c0659e commit 18f4e07
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/dep/ensure.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func (cmd *ensureCommand) runVendorOnly(ctx *dep.Ctx, args []string, p *dep.Proj

// Pass the same lock as old and new so that the writer will observe no
// difference, and write out only ncessary vendor/ changes.
dw, err := dep.NewSafeWriter(nil, p.Lock, p.Lock, dep.VendorAlways, p.Manifest.PruneOptions)
dw, err := dep.NewSafeWriter(nil, p.Lock, p.Lock, dep.VendorAlways, p.Manifest.PruneOptions, nil)
//dw, err := dep.NewDeltaWriter(p.Lock, p.Lock, p.Manifest.PruneOptions, filepath.Join(p.AbsRoot, "vendor"), dep.VendorAlways)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/dep/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
ctx.Err.Printf("Old vendor backed up to %v", vendorbak)
}

sw, err := dep.NewSafeWriter(p.Manifest, nil, p.Lock, dep.VendorAlways, p.Manifest.PruneOptions)
sw, err := dep.NewSafeWriter(p.Manifest, nil, p.Lock, dep.VendorAlways, p.Manifest.PruneOptions, nil)
if err != nil {
return errors.Wrap(err, "init failed: unable to create a SafeWriter")
}
Expand Down
17 changes: 14 additions & 3 deletions txn_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ type SafeWriter struct {
// - If oldLock is provided without newLock, error.
//
// - If vendor is VendorAlways without a newLock, error.
func NewSafeWriter(manifest *Manifest, oldLock, newLock *Lock, vendor VendorBehavior, prune gps.CascadingPruneOptions) (*SafeWriter, error) {
func NewSafeWriter(manifest *Manifest, oldLock, newLock *Lock, vendor VendorBehavior, prune gps.CascadingPruneOptions, status map[string]verify.VendorStatus) (*SafeWriter, error) {
sw := &SafeWriter{
Manifest: manifest,
lock: newLock,
Expand All @@ -114,7 +114,18 @@ func NewSafeWriter(manifest *Manifest, oldLock, newLock *Lock, vendor VendorBeha
case VendorAlways:
sw.writeVendor = true
case VendorOnChanged:
sw.writeVendor = sw.lockDiff.Changed(anyExceptHash & ^verify.InputImportsChanged) || (newLock != nil && oldLock == nil)
if newLock != nil && oldLock == nil {
sw.writeVendor = true
} else if sw.lockDiff.Changed(anyExceptHash & ^verify.InputImportsChanged) {
sw.writeVendor = true
} else {
for _, stat := range status {
if stat != verify.NoMismatch {
sw.writeVendor = true
break
}
}
}
}

if sw.writeVendor && newLock == nil {
Expand Down Expand Up @@ -442,7 +453,7 @@ func NewDeltaWriter(oldLock, newLock *Lock, status map[string]verify.VendorStatu
if err != nil && os.IsNotExist(err) {
// Provided dir does not exist, so there's no disk contents to compare
// against. Fall back to the old SafeWriter.
return NewSafeWriter(nil, oldLock, newLock, behavior, prune)
return NewSafeWriter(nil, oldLock, newLock, behavior, prune, status)
}

sw.lockDiff = verify.DiffLocks(oldLock, newLock)
Expand Down

0 comments on commit 18f4e07

Please sign in to comment.