@@ -423,10 +423,11 @@ type DeltaWriter struct {
423
423
type changeType uint8
424
424
425
425
const (
426
- solveChanged changeType = iota + 1
427
- hashMismatch
426
+ hashMismatch changeType = iota + 1
428
427
hashVersionMismatch
429
428
hashAbsent
429
+ noVerify
430
+ solveChanged
430
431
pruneOptsChanged
431
432
missingFromTree
432
433
projectAdded
@@ -437,10 +438,10 @@ const (
437
438
// directory by writing out only those projects that actually need to be written
438
439
// out - they have changed in some way, or they lack the necessary hash
439
440
// information to be verified.
440
- func NewDeltaWriter (oldLock , newLock * Lock , status map [ string ]verify. VendorStatus , prune gps. CascadingPruneOptions , vendorDir string , behavior VendorBehavior ) (TreeWriter , error ) {
441
- sw := & DeltaWriter {
441
+ func NewDeltaWriter (p * Project , newLock * Lock , behavior VendorBehavior ) (TreeWriter , error ) {
442
+ dw := & DeltaWriter {
442
443
lock : newLock ,
443
- vendorDir : vendorDir ,
444
+ vendorDir : filepath . Join ( p . AbsRoot , "vendor" ) ,
444
445
changed : make (map [gps.ProjectRoot ]changeType ),
445
446
behavior : behavior ,
446
447
}
@@ -449,27 +450,35 @@ func NewDeltaWriter(oldLock, newLock *Lock, status map[string]verify.VendorStatu
449
450
return nil , errors .New ("must provide a non-nil newlock" )
450
451
}
451
452
452
- _ , err := os .Stat (vendorDir )
453
- if err != nil && os .IsNotExist (err ) {
454
- // Provided dir does not exist, so there's no disk contents to compare
455
- // against. Fall back to the old SafeWriter.
456
- return NewSafeWriter (nil , oldLock , newLock , behavior , prune , status )
453
+ status , err := p .VerifyVendor ()
454
+ if err != nil {
455
+ return nil , err
457
456
}
458
457
459
- sw .lockDiff = verify .DiffLocks (oldLock , newLock )
458
+ _ , err = os .Stat (dw .vendorDir )
459
+ if err != nil {
460
+ if os .IsNotExist (err ) {
461
+ // Provided dir does not exist, so there's no disk contents to compare
462
+ // against. Fall back to the old SafeWriter.
463
+ return NewSafeWriter (nil , p .Lock , newLock , behavior , p .Manifest .PruneOptions , status )
464
+ }
465
+ return nil , err
466
+ }
460
467
461
- for pr , lpd := range sw .lockDiff .ProjectDeltas {
468
+ dw .lockDiff = verify .DiffLocks (p .Lock , newLock )
469
+
470
+ for pr , lpd := range dw .lockDiff .ProjectDeltas {
462
471
// Hash changes aren't relevant at this point, as they could be empty
463
472
// in the new lock, and therefore a symptom of a solver change.
464
473
if lpd .Changed (anyExceptHash ) {
465
474
if lpd .WasAdded () {
466
- sw .changed [pr ] = projectAdded
475
+ dw .changed [pr ] = projectAdded
467
476
} else if lpd .WasRemoved () {
468
- sw .changed [pr ] = projectRemoved
477
+ dw .changed [pr ] = projectRemoved
469
478
} else if lpd .PruneOptsChanged () {
470
- sw .changed [pr ] = pruneOptsChanged
479
+ dw .changed [pr ] = pruneOptsChanged
471
480
} else {
472
- sw .changed [pr ] = solveChanged
481
+ dw .changed [pr ] = solveChanged
473
482
}
474
483
}
475
484
}
@@ -478,23 +487,44 @@ func NewDeltaWriter(oldLock, newLock *Lock, status map[string]verify.VendorStatu
478
487
pr := gps .ProjectRoot (spr )
479
488
// These cases only matter if there was no change already recorded via
480
489
// the differ.
481
- if _ , has := sw .changed [pr ]; ! has {
490
+ if _ , has := dw .changed [pr ]; ! has {
482
491
switch stat {
483
492
case verify .NotInTree :
484
- sw .changed [pr ] = missingFromTree
493
+ dw .changed [pr ] = missingFromTree
485
494
case verify .NotInLock :
486
- sw .changed [pr ] = projectRemoved
495
+ dw .changed [pr ] = projectRemoved
487
496
case verify .DigestMismatchInLock :
488
- sw .changed [pr ] = hashMismatch
497
+ dw .changed [pr ] = hashMismatch
489
498
case verify .HashVersionMismatch :
490
- sw .changed [pr ] = hashVersionMismatch
499
+ dw .changed [pr ] = hashVersionMismatch
491
500
case verify .EmptyDigestInLock :
492
- sw .changed [pr ] = hashAbsent
501
+ dw .changed [pr ] = hashAbsent
493
502
}
494
503
}
495
504
}
496
505
497
- return sw , nil
506
+ // Apply noverify last, as it should only supersede changeTypes with lower
507
+ // values. It is NOT applied if no existing change is registered.
508
+ for _ , spr := range p .Manifest .NoVerify {
509
+ pr := gps .ProjectRoot (spr )
510
+ // We don't validate this field elsewhere as it can be difficult to know
511
+ // at the beginning of a dep ensure command whether or not the noverify
512
+ // project actually will exist as part of the Lock by the end of the
513
+ // run. So, only apply if it's in the lockdiff, and isn't a removal.
514
+ if _ , has := dw .lockDiff .ProjectDeltas [pr ]; has {
515
+ if typ , has := dw .changed [pr ]; has && typ < noVerify {
516
+ // Avoid writing noverify projects at all for the lower change
517
+ // types.
518
+ delete (dw .changed , pr )
519
+
520
+ // Uncomment this if we want to switch to the safer behavior,
521
+ // where we ALWAYS write noverify projects.
522
+ //dw.changed[pr] = noVerify
523
+ }
524
+ }
525
+ }
526
+
527
+ return dw , nil
498
528
}
499
529
500
530
// Write executes the planned changes.
@@ -659,6 +689,8 @@ func (dw *DeltaWriter) Write(path string, sm gps.SourceManager, examples bool, l
659
689
// possible changeType.
660
690
func changeExplanation (c changeType , lpd verify.LockedProjectDelta ) string {
661
691
switch c {
692
+ case noVerify :
693
+ return "verification is disabled"
662
694
case solveChanged :
663
695
if lpd .SourceChanged () {
664
696
return fmt .Sprintf ("source changed (%s -> %s)" , lpd .SourceBefore , lpd .SourceAfter )
@@ -675,9 +707,8 @@ func changeExplanation(c changeType, lpd verify.LockedProjectDelta) string {
675
707
return fmt .Sprintf ("packages changed (%v added, %v removed)" , la , lr )
676
708
} else if la > 0 {
677
709
return fmt .Sprintf ("packages changed (%v added)" , la )
678
- } else {
679
- return fmt .Sprintf ("packages changed (%v removed)" , lr )
680
710
}
711
+ return fmt .Sprintf ("packages changed (%v removed)" , lr )
681
712
}
682
713
case pruneOptsChanged :
683
714
// Override what's on the lockdiff with the extra info we have;
0 commit comments