MCPcopy Index your code
hub / github.com/tailscale/tailscale / updateDebianAptSourcesListBytes

Function updateDebianAptSourcesListBytes

clientupdate/clientupdate.go:521–554  ·  view source on GitHub ↗
(was []byte, dstTrack string)

Source from the content-addressed store, hash-verified

519}
520
521func updateDebianAptSourcesListBytes(was []byte, dstTrack string) (newContent []byte, err error) {
522 trackURLPrefix := []byte("https://pkgs.tailscale.com/" + dstTrack + "/")
523 var buf bytes.Buffer
524 var changes int
525 bs := bufio.NewScanner(bytes.NewReader(was))
526 hadCorrect := false
527 commentLine := regexp.MustCompile(`^\s*\#`)
528 pkgsURL := regexp.MustCompile(`\bhttps://pkgs\.tailscale\.com/(stable|unstable|release-candidate)/`)
529 for bs.Scan() {
530 line := bs.Bytes()
531 if !commentLine.Match(line) {
532 line = pkgsURL.ReplaceAllFunc(line, func(m []byte) []byte {
533 if bytes.Equal(m, trackURLPrefix) {
534 hadCorrect = true
535 } else {
536 changes++
537 }
538 return trackURLPrefix
539 })
540 }
541 buf.Write(line)
542 buf.WriteByte('\n')
543 }
544 if hadCorrect || (changes == 1 && bytes.Equal(bytes.TrimSpace(was), bytes.TrimSpace(buf.Bytes()))) {
545 // Unchanged or close enough.
546 return was, nil
547 }
548 if changes != 1 {
549 // No changes, or an unexpected number of changes (what?). Bail.
550 // They probably editted it by hand and we don't know what to do.
551 return nil, fmt.Errorf("unexpected/unsupported %s contents", aptSourcesFile)
552 }
553 return buf.Bytes(), nil
554}
555
556func (up *Updater) archPackageInstalled() bool {
557 err := exec.Command("pacman", "--query", "tailscale").Run()

Callers 2

Calls 6

WriteMethod · 0.95
ScanMethod · 0.80
BytesMethod · 0.80
MatchMethod · 0.80
EqualMethod · 0.65
ErrorfMethod · 0.65

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…