mirror of
https://github.com/containers/podman.git
synced 2025-06-23 02:18:13 +08:00
systemd.parser: Add GetTemplateParts()
This helper splits out a templated filename into the base template and the instance name. This will be used later. Signed-off-by: Alexander Larsson <alexl@redhat.com>
This commit is contained in:
@ -7,6 +7,7 @@ import (
|
||||
"os"
|
||||
"os/user"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode"
|
||||
@ -919,3 +920,13 @@ func (f *UnitFile) PrependComment(groupName string, comments ...string) {
|
||||
group.prependComment(newUnitLine("", "# "+comments[i], true))
|
||||
}
|
||||
}
|
||||
|
||||
func (f *UnitFile) GetTemplateParts() (string, string) {
|
||||
ext := filepath.Ext(f.Filename)
|
||||
basename := strings.TrimSuffix(f.Filename, ext)
|
||||
parts := strings.SplitN(basename, "@", 2)
|
||||
if len(parts) < 2 {
|
||||
return "", ""
|
||||
}
|
||||
return parts[0] + "@" + ext, parts[1]
|
||||
}
|
||||
|
Reference in New Issue
Block a user