github.com/nilium/gitlab-runner@v12.5.0+incompatible/helpers/archives/path_error_tracker.go (about) 1 package archives 2 3 import ( 4 "os" 5 "sync" 6 ) 7 8 // When extracting an archive, the same PathError.Op may be repeated for every 9 // file in the archive; use pathErrorTracker to suppress repetitious log output 10 type pathErrorTracker struct { 11 sync.Mutex 12 seenOps map[string]bool 13 } 14 15 // check whether the error is actionable, which is to say, not nil and either 16 // not a PathError, or a novel PathError 17 func (p *pathErrorTracker) actionable(e error) bool { 18 pathErr, isPathErr := e.(*os.PathError) 19 if e == nil || isPathErr && pathErr == nil { 20 return false 21 } 22 23 if !isPathErr { 24 return true 25 } 26 27 p.Lock() 28 defer p.Unlock() 29 30 seen := p.seenOps[pathErr.Op] 31 p.seenOps[pathErr.Op] = true 32 33 // actionable if *not* seen before 34 return !seen 35 } 36 37 func newPathErrorTracker() *pathErrorTracker { 38 return &pathErrorTracker{ 39 seenOps: make(map[string]bool), 40 } 41 }