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

Commit 18f4e07

Browse files
committed
dep: Make SafeWriter use status map for OnChanged
If vendor was empty, nonexistent, or just missing a few targeted items, the SafeWriter would miss them.
1 parent 2c0659e commit 18f4e07

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

cmd/dep/ensure.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ func (cmd *ensureCommand) runVendorOnly(ctx *dep.Ctx, args []string, p *dep.Proj
316316

317317
// Pass the same lock as old and new so that the writer will observe no
318318
// difference, and write out only ncessary vendor/ changes.
319-
dw, err := dep.NewSafeWriter(nil, p.Lock, p.Lock, dep.VendorAlways, p.Manifest.PruneOptions)
319+
dw, err := dep.NewSafeWriter(nil, p.Lock, p.Lock, dep.VendorAlways, p.Manifest.PruneOptions, nil)
320320
//dw, err := dep.NewDeltaWriter(p.Lock, p.Lock, p.Manifest.PruneOptions, filepath.Join(p.AbsRoot, "vendor"), dep.VendorAlways)
321321
if err != nil {
322322
return err

cmd/dep/init.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
170170
ctx.Err.Printf("Old vendor backed up to %v", vendorbak)
171171
}
172172

173-
sw, err := dep.NewSafeWriter(p.Manifest, nil, p.Lock, dep.VendorAlways, p.Manifest.PruneOptions)
173+
sw, err := dep.NewSafeWriter(p.Manifest, nil, p.Lock, dep.VendorAlways, p.Manifest.PruneOptions, nil)
174174
if err != nil {
175175
return errors.Wrap(err, "init failed: unable to create a SafeWriter")
176176
}

txn_writer.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ type SafeWriter struct {
9090
// - If oldLock is provided without newLock, error.
9191
//
9292
// - If vendor is VendorAlways without a newLock, error.
93-
func NewSafeWriter(manifest *Manifest, oldLock, newLock *Lock, vendor VendorBehavior, prune gps.CascadingPruneOptions) (*SafeWriter, error) {
93+
func NewSafeWriter(manifest *Manifest, oldLock, newLock *Lock, vendor VendorBehavior, prune gps.CascadingPruneOptions, status map[string]verify.VendorStatus) (*SafeWriter, error) {
9494
sw := &SafeWriter{
9595
Manifest: manifest,
9696
lock: newLock,
@@ -114,7 +114,18 @@ func NewSafeWriter(manifest *Manifest, oldLock, newLock *Lock, vendor VendorBeha
114114
case VendorAlways:
115115
sw.writeVendor = true
116116
case VendorOnChanged:
117-
sw.writeVendor = sw.lockDiff.Changed(anyExceptHash & ^verify.InputImportsChanged) || (newLock != nil && oldLock == nil)
117+
if newLock != nil && oldLock == nil {
118+
sw.writeVendor = true
119+
} else if sw.lockDiff.Changed(anyExceptHash & ^verify.InputImportsChanged) {
120+
sw.writeVendor = true
121+
} else {
122+
for _, stat := range status {
123+
if stat != verify.NoMismatch {
124+
sw.writeVendor = true
125+
break
126+
}
127+
}
128+
}
118129
}
119130

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

448459
sw.lockDiff = verify.DiffLocks(oldLock, newLock)

0 commit comments

Comments
 (0)