Skip to content

Commit

Permalink
feat: move validation to proper function
Browse files Browse the repository at this point in the history
Signed-off-by: Smuu <[email protected]>
  • Loading branch information
smuu committed Dec 6, 2024
1 parent 34a7443 commit bc44e4e
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions pkg/instance/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bc44e4e

Please sign in to comment.