From bc44e4eee7626f30b48e25e796b0204f5889a4e4 Mon Sep 17 00:00:00 2001 From: Smuu <18609909+Smuu@users.noreply.github.com> Date: Fri, 6 Dec 2024 10:48:05 +0100 Subject: [PATCH] feat: move validation to proper function Signed-off-by: Smuu <18609909+Smuu@users.noreply.github.com> --- pkg/instance/storage.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/pkg/instance/storage.go b/pkg/instance/storage.go index 86c5135..bc27ed7 100644 --- a/pkg/instance/storage.go +++ b/pkg/instance/storage.go @@ -256,6 +256,13 @@ func (s *storage) validateFileArgs(src, dest, chown string) error { if !strings.Contains(chown, ":") || len(strings.Split(chown, ":")) != 2 { return ErrChownMustBeInFormatUserGroup } + + parts := strings.Split(chown, ":") + for _, part := range parts { + if _, err := strconv.ParseInt(part, 10, 64); err != nil { + return ErrFailedToConvertToInt64.WithParams(part).Wrap(err) + } + } return nil } @@ -307,15 +314,6 @@ func (s *storage) addFileToInstance(srcPath, dest, chown string) error { // get the permission of the src file permission := fmt.Sprintf("%o", srcInfo.Mode().Perm()) - parts := strings.Split(chown, ":") - if len(parts) != 2 { - return ErrInvalidFormat.WithParams(chown) - } - for _, part := range parts { - if _, err := strconv.ParseInt(part, 10, 64); err != nil { - return ErrFailedToConvertToInt64.WithParams(part).Wrap(err) - } - } file := s.instance.K8sClient.NewFile(srcPath, dest, chown, permission) s.files = append(s.files, file)