func()

in packaging/linux/rpm/template.go [703:845]


func (w *specWrapper) Files() fmt.Stringer {
	b := &strings.Builder{}
	fmt.Fprintf(b, "%%files\n")

	artifacts := w.GetArtifacts(w.Target)

	if len(artifacts.Binaries) > 0 {
		binKeys := dalec.SortMapKeys(artifacts.Binaries)
		for _, p := range binKeys {
			cfg := artifacts.Binaries[p]
			full := filepath.Join(`%{_bindir}/`, cfg.SubPath, cfg.ResolveName(p))
			fmt.Fprintln(b, full)
		}
	}

	if len(artifacts.Manpages) > 0 {
		fmt.Fprintln(b, `%{_mandir}/*/*`)
	}

	if artifacts.Directories != nil {
		configKeys := dalec.SortMapKeys(artifacts.Directories.Config)
		for _, p := range configKeys {
			dir := strings.Join([]string{`%dir`, filepath.Join(`%{_sysconfdir}`, p)}, " ")
			fmt.Fprintln(b, dir)
		}

		stateKeys := dalec.SortMapKeys(artifacts.Directories.State)
		for _, p := range stateKeys {
			dir := strings.Join([]string{`%dir`, filepath.Join(`%{_sharedstatedir}`, p)}, " ")
			fmt.Fprintln(b, dir)
		}
	}

	if artifacts.DataDirs != nil {
		dataKeys := dalec.SortMapKeys(artifacts.DataDirs)
		for _, k := range dataKeys {
			df := artifacts.DataDirs[k]
			fullPath := filepath.Join(`%{_datadir}`, df.SubPath, df.ResolveName(k))
			fmt.Fprintln(b, fullPath)
		}
	}

	if artifacts.Libexec != nil {
		dataKeys := dalec.SortMapKeys(artifacts.Libexec)
		for _, k := range dataKeys {
			le := artifacts.Libexec[k]
			targetDir := filepath.Join(`%{_libexecdir}`, le.SubPath)
			fullPath := filepath.Join(targetDir, le.ResolveName(k))
			fmt.Fprintln(b, fullPath)
		}
	}

	configKeys := dalec.SortMapKeys(artifacts.ConfigFiles)
	for _, c := range configKeys {
		cfg := artifacts.ConfigFiles[c]
		fullPath := filepath.Join(`%{_sysconfdir}`, cfg.SubPath, cfg.ResolveName(c))
		fullDirective := strings.Join([]string{`%config(noreplace)`, fullPath}, " ")
		fmt.Fprintln(b, fullDirective)
	}

	if artifacts.Systemd != nil {
		serviceKeys := dalec.SortMapKeys(artifacts.Systemd.Units)
		for _, p := range serviceKeys {
			cfg := artifacts.Systemd.Units[p]
			a := cfg.Artifact()
			unitPath := filepath.Join(`%{_unitdir}/`, a.SubPath, a.ResolveName(p))
			fmt.Fprintln(b, unitPath)
		}

		dropins := make(map[string][]string)
		// process these to get a unique list of files per unit name.
		// we need a single dir entry for the directory
		// need a file entry for each of files
		dropinKeys := dalec.SortMapKeys(artifacts.Systemd.Dropins)
		for _, d := range dropinKeys {
			cfg := artifacts.Systemd.Dropins[d]
			art := cfg.Artifact()
			files, ok := dropins[cfg.Unit]
			if !ok {
				files = []string{}
			}
			p := filepath.Join(
				`%{_unitdir}`,
				fmt.Sprintf("%s.d", cfg.Unit),
				art.ResolveName(d),
			)
			dropins[cfg.Unit] = append(files, p)
		}
		unitNames := dalec.SortMapKeys(dropins)
		for _, u := range unitNames {
			dir := strings.Join([]string{
				`%dir`,
				filepath.Join(
					`%{_unitdir}`,
					fmt.Sprintf("%s.d", u),
				),
			}, " ")
			fmt.Fprintln(b, dir)

			for _, file := range dropins[u] {
				fmt.Fprintln(b, file)
			}
		}
	}

	docKeys := dalec.SortMapKeys(artifacts.Docs)
	for _, d := range docKeys {
		cfg := artifacts.Docs[d]
		path := filepath.Join(`%{_docdir}`, w.Name, cfg.SubPath, cfg.ResolveName(d))
		fullDirective := strings.Join([]string{`%doc`, path}, " ")
		fmt.Fprintln(b, fullDirective)
	}

	licenseKeys := dalec.SortMapKeys(artifacts.Licenses)
	for _, l := range licenseKeys {
		cfg := artifacts.Licenses[l]
		path := filepath.Join(`%{_licensedir}`, w.Name, cfg.SubPath, cfg.ResolveName(l))
		fullDirective := strings.Join([]string{`%license`, path}, " ")
		fmt.Fprintln(b, fullDirective)
	}

	libKeys := dalec.SortMapKeys(artifacts.Libs)
	for _, l := range libKeys {
		cfg := artifacts.Libs[l]
		path := filepath.Join(`%{_libdir}`, cfg.SubPath, cfg.ResolveName(l))
		fmt.Fprintln(b, path)
	}

	for _, l := range artifacts.Links {
		fmt.Fprintln(b, l.Dest)
	}

	if len(artifacts.Headers) > 0 {
		headersKeys := dalec.SortMapKeys(artifacts.Headers)
		for _, h := range headersKeys {
			hf := artifacts.Headers[h]
			path := filepath.Join(`%{_includedir}`, hf.SubPath, hf.ResolveName(h))
			fmt.Fprintln(b, path)
		}
	}
	b.WriteString("\n")
	return b
}