File: config.go

package info (click to toggle)
acmetool 0.2.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 792 kB
  • sloc: sh: 349; makefile: 105
file content (41 lines) | stat: -rw-r--r-- 908 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package storageops

import "github.com/hlandau/acmetool/storage"

// Update targets to remove any mention of hostname from all targets. The
// targets are resaved to disk.
func RemoveTargetHostname(s storage.Store, hostname string) error {
	return s.VisitTargets(func(t *storage.Target) error {
		if !containsName(t.Satisfy.Names, hostname) {
			return nil // continue
		}

		t.Satisfy.Names = removeStringFromList(t.Satisfy.Names, hostname)
		t.Request.Names = removeStringFromList(t.Request.Names, hostname)

		if len(t.Satisfy.Names) == 0 {
			return s.RemoveTarget(t.Filename)
		}

		return s.SaveTarget(t)
	})
}

func containsName(names []string, name string) bool {
	for _, n := range names {
		if n == name {
			return true
		}
	}
	return false
}

func removeStringFromList(ss []string, s string) []string {
	var r []string
	for _, x := range ss {
		if x != s {
			r = append(r, x)
		}
	}
	return r
}