diff --git a/cmd/podman/parse/net.go b/cmd/podman/parse/net.go index 147991791b..0d7390592e 100644 --- a/cmd/podman/parse/net.go +++ b/cmd/podman/parse/net.go @@ -8,9 +8,9 @@ import ( "net" "net/url" "os" - "regexp" "strings" - "sync" + + "github.com/containers/storage/pkg/regexp" ) const ( @@ -23,9 +23,8 @@ const ( var ( whiteSpaces = " \t" - alphaRegexp *regexp.Regexp - domainRegexp *regexp.Regexp - onceRegex sync.Once + alphaRegexp = regexp.Delayed(`[a-zA-Z]`) + domainRegexp = regexp.Delayed(`^(:?(:?[a-zA-Z0-9]|(:?[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9]))(:?\.(:?[a-zA-Z0-9]|(:?[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])))*)\.?\s*$`) ) // validateExtraHost validates that the specified string is a valid extrahost and returns it. @@ -54,10 +53,6 @@ func validateIPAddress(val string) (string, error) { } func ValidateDomain(val string) (string, error) { - onceRegex.Do(func() { - alphaRegexp = regexp.MustCompile(`[a-zA-Z]`) - domainRegexp = regexp.MustCompile(`^(:?(:?[a-zA-Z0-9]|(:?[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9]))(:?\.(:?[a-zA-Z0-9]|(:?[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])))*)\.?\s*$`) - }) if alphaRegexp.FindString(val) == "" { return "", fmt.Errorf("%s is not a valid domain", val) } diff --git a/libpod/options.go b/libpod/options.go index 99ee39a640..d9a6f99765 100644 --- a/libpod/options.go +++ b/libpod/options.go @@ -6,9 +6,7 @@ import ( "net" "os" "path/filepath" - "regexp" "strings" - "sync" "syscall" "github.com/containers/buildah/pkg/parse" @@ -25,15 +23,13 @@ import ( "github.com/containers/podman/v4/pkg/util" "github.com/containers/storage" "github.com/containers/storage/pkg/idtools" + "github.com/containers/storage/pkg/regexp" "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/generate" "github.com/sirupsen/logrus" ) -var ( - umaskRegex *regexp.Regexp - onceRegex sync.Once -) +var umaskRegex = regexp.Delayed(`^[0-7]{1,4}$`) // WithStorageConfig uses the given configuration to set up container storage. // If this is not specified, the system default configuration will be used @@ -1797,9 +1793,6 @@ func WithTimezone(path string) CtrCreateOption { // WithUmask sets the umask in the container func WithUmask(umask string) CtrCreateOption { - onceRegex.Do(func() { - umaskRegex = regexp.MustCompile(`^[0-7]{1,4}$`) - }) return func(ctr *Container) error { if ctr.valid { return define.ErrCtrFinalized diff --git a/pkg/bindings/images/build.go b/pkg/bindings/images/build.go index 1ea74f3154..98686f6944 100644 --- a/pkg/bindings/images/build.go +++ b/pkg/bindings/images/build.go @@ -13,11 +13,9 @@ import ( "net/url" "os" "path/filepath" - "regexp" "runtime" "strconv" "strings" - "sync" "github.com/containers/buildah/define" "github.com/containers/image/v5/types" @@ -26,6 +24,7 @@ import ( "github.com/containers/podman/v4/pkg/domain/entities" "github.com/containers/storage/pkg/fileutils" "github.com/containers/storage/pkg/ioutils" + "github.com/containers/storage/pkg/regexp" "github.com/docker/go-units" "github.com/hashicorp/go-multierror" jsoniter "github.com/json-iterator/go" @@ -37,17 +36,10 @@ type devino struct { Ino uint64 } -var ( - iidRegex *regexp.Regexp - onceRegex sync.Once -) +var iidRegex = regexp.Delayed(`^[0-9a-f]{12}`) // Build creates an image using a containerfile reference func Build(ctx context.Context, containerFiles []string, options entities.BuildOptions) (*entities.BuildReport, error) { - onceRegex.Do(func() { - iidRegex = regexp.MustCompile(`^[0-9a-f]{12}`) - }) - if options.CommonBuildOpts == nil { options.CommonBuildOpts = new(define.CommonBuildOptions) } diff --git a/pkg/systemd/quadlet/quadlet.go b/pkg/systemd/quadlet/quadlet.go index 89768b8ee3..5254e2c956 100644 --- a/pkg/systemd/quadlet/quadlet.go +++ b/pkg/systemd/quadlet/quadlet.go @@ -3,11 +3,10 @@ package quadlet import ( "fmt" "path/filepath" - "regexp" "strings" - "sync" "github.com/containers/podman/v4/pkg/systemd/parser" + "github.com/containers/storage/pkg/regexp" ) const ( @@ -75,8 +74,7 @@ const ( ) var ( - onceRegex sync.Once - validPortRange *regexp.Regexp + validPortRange = regexp.Delayed(`\d+(-\d+)?(/udp|/tcp)?$`) // Supported keys in "Container" group supportedContainerKeys = map[string]bool{ @@ -157,9 +155,6 @@ func replaceExtension(name string, extension string, extraPrefix string, extraSu } func isPortRange(port string) bool { - onceRegex.Do(func() { - validPortRange = regexp.MustCompile(`\d+(-\d+)?(/udp|/tcp)?$`) - }) return validPortRange.MatchString(port) }