This is an automated email from the ASF dual-hosted git repository.

tsato pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit a01da91dcb088632a98b50eb76fdc3c60f23671b
Author: Tadayoshi Sato <sato.tadayo...@gmail.com>
AuthorDate: Thu Jul 14 15:46:04 2022 +0900

    chore(lint): fix nonamedreturns
---
 addons/master/master.go              |  3 ++-
 cmd/util/platform-check/main.go      |  2 +-
 pkg/cmd/dump.go                      |  4 ++--
 pkg/cmd/log.go                       |  2 +-
 pkg/cmd/run.go                       |  2 +-
 pkg/event/manager.go                 |  5 +++--
 pkg/trait/affinity.go                |  2 +-
 pkg/trait/cron.go                    |  3 ++-
 pkg/trait/jolokia.go                 |  2 +-
 pkg/trait/pod.go                     | 12 +++++++-----
 pkg/trait/prometheus.go              |  2 +-
 pkg/trait/toleration.go              |  2 +-
 pkg/trait/trait_types.go             |  3 ++-
 pkg/util/command.go                  | 21 ++++++++++-----------
 pkg/util/kubernetes/portforward.go   |  2 +-
 pkg/util/maven/maven_log.go          |  7 ++++---
 pkg/util/maven/maven_repositories.go |  5 +++--
 pkg/util/modeline/parser.go          |  6 ++++--
 pkg/util/resource/config.go          |  8 ++++----
 pkg/util/source/inspector_kamelet.go |  7 ++++---
 pkg/util/test/client.go              |  7 ++++---
 pkg/util/test/cmd.go                 |  8 ++++----
 pkg/util/util.go                     | 29 ++++++++++++++---------------
 23 files changed, 77 insertions(+), 67 deletions(-)

diff --git a/addons/master/master.go b/addons/master/master.go
index 7c002b539..31ae161fd 100644
--- a/addons/master/master.go
+++ b/addons/master/master.go
@@ -228,7 +228,8 @@ func (t *masterTrait) canUseLeases(e *trait.Environment) 
(bool, error) {
        return kubernetes.CheckPermission(e.Ctx, t.Client, 
"coordination.k8s.io", "leases", e.Integration.Namespace, "", "create")
 }
 
-func findAdditionalDependencies(e *trait.Environment, meta 
metadata.IntegrationMetadata) (dependencies []string) {
+func findAdditionalDependencies(e *trait.Environment, meta 
metadata.IntegrationMetadata) []string {
+       var dependencies []string
        for _, endpoint := range meta.FromURIs {
                if uri.GetComponent(endpoint) == masterComponent {
                        parts := strings.Split(endpoint, ":")
diff --git a/cmd/util/platform-check/main.go b/cmd/util/platform-check/main.go
index 34e71773d..4b052b279 100644
--- a/cmd/util/platform-check/main.go
+++ b/cmd/util/platform-check/main.go
@@ -53,7 +53,7 @@ func exitOnError(err error) {
        }
 }
 
-func RestConfig() (c *rest.Config) {
+func RestConfig() *rest.Config {
        restConfig, err := config.GetConfig()
        exitOnError(err)
 
diff --git a/pkg/cmd/dump.go b/pkg/cmd/dump.go
index 1fb6cdc65..16e8e4c4b 100644
--- a/pkg/cmd/dump.go
+++ b/pkg/cmd/dump.go
@@ -60,10 +60,10 @@ type dumpCmdOptions struct {
        Compressed bool `mapstructure:"compressed" yaml:",omitempty"`
 }
 
-func (o *dumpCmdOptions) dump(cmd *cobra.Command, args []string) (err error) {
+func (o *dumpCmdOptions) dump(cmd *cobra.Command, args []string) error {
        c, err := o.GetCmdClient()
        if err != nil {
-               return
+               return err
        }
 
        if len(args) == 1 {
diff --git a/pkg/cmd/log.go b/pkg/cmd/log.go
index bfa82910c..9a9efcbf9 100644
--- a/pkg/cmd/log.go
+++ b/pkg/cmd/log.go
@@ -92,7 +92,7 @@ func (o *logCmdOptions) run(cmd *cobra.Command, args 
[]string) error {
        currLogMsg := ""
        newLogMsg := ""
 
-       err = wait.PollImmediate(pollInterval, pollTimeout, func() (done bool, 
err error) {
+       err = wait.PollImmediate(pollInterval, pollTimeout, func() (bool, 
error) {
                //
                // Reduce repetition of messages by tracking the last message
                // and checking if its different from the new message
diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index 9a02f5064..a1a8894d0 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -792,7 +792,7 @@ func loadPropertyFile(fileName string) 
(*properties.Properties, error) {
        return p, nil
 }
 
-func resolvePodTemplate(ctx context.Context, cmd *cobra.Command, templateSrc 
string, spec *v1.IntegrationSpec) (err error) {
+func resolvePodTemplate(ctx context.Context, cmd *cobra.Command, templateSrc 
string, spec *v1.IntegrationSpec) error {
        // check if template is set
        if templateSrc == "" {
                return nil
diff --git a/pkg/event/manager.go b/pkg/event/manager.go
index e9629f3b2..d6af7dfa7 100644
--- a/pkg/event/manager.go
+++ b/pkg/event/manager.go
@@ -294,12 +294,13 @@ func notifyIfConditionUpdated(recorder 
record.EventRecorder, newResource runtime
        }
 }
 
-func getCommonChangedConditions(oldConditions, newConditions 
[]v1.ResourceCondition) (res []v1.ResourceCondition) {
+func getCommonChangedConditions(oldConditions, newConditions 
[]v1.ResourceCondition) []v1.ResourceCondition {
        oldState := make(map[string]v1.ResourceCondition)
        for _, c := range oldConditions {
                oldState[c.GetType()] = c
        }
 
+       var res []v1.ResourceCondition
        for _, newCond := range newConditions {
                oldCond := oldState[newCond.GetType()]
                if oldCond == nil || oldCond.GetStatus() != newCond.GetStatus() 
|| oldCond.GetMessage() != newCond.GetMessage() {
@@ -309,7 +310,7 @@ func getCommonChangedConditions(oldConditions, 
newConditions []v1.ResourceCondit
        return res
 }
 
-func getCreatorObject(ctx context.Context, c client.Client, obj 
runtime.Object) (ref *corev1.ObjectReference, creator runtime.Object) {
+func getCreatorObject(ctx context.Context, c client.Client, obj 
runtime.Object) (*corev1.ObjectReference, runtime.Object) {
        if ref := kubernetes.GetCamelCreator(obj); ref != nil {
                if ref.Kind == "Integration" {
                        it := v1.NewIntegration(ref.Namespace, ref.Name)
diff --git a/pkg/trait/affinity.go b/pkg/trait/affinity.go
index 051299fc2..dc67b1785 100644
--- a/pkg/trait/affinity.go
+++ b/pkg/trait/affinity.go
@@ -58,7 +58,7 @@ func (t *affinityTrait) Configure(e *Environment) (bool, 
error) {
        return e.IntegrationInRunningPhases(), nil
 }
 
-func (t *affinityTrait) Apply(e *Environment) (err error) {
+func (t *affinityTrait) Apply(e *Environment) error {
        podSpec := e.GetIntegrationPodSpec()
 
        if podSpec == nil {
diff --git a/pkg/trait/cron.go b/pkg/trait/cron.go
index 62adad38e..f3355492a 100644
--- a/pkg/trait/cron.go
+++ b/pkg/trait/cron.go
@@ -355,7 +355,8 @@ func (t *cronTrait) getSourcesFromURIs(e *Environment) 
([]string, error) {
        return meta.FromURIs, nil
 }
 
-func getCronForURIs(camelURIs []string) (globalCron *cronInfo) {
+func getCronForURIs(camelURIs []string) *cronInfo {
+       var globalCron *cronInfo
        for _, camelURI := range camelURIs {
                cr := getCronForURI(camelURI)
                if cr == nil {
diff --git a/pkg/trait/jolokia.go b/pkg/trait/jolokia.go
index 2ca5c134f..0e1fc51d4 100644
--- a/pkg/trait/jolokia.go
+++ b/pkg/trait/jolokia.go
@@ -52,7 +52,7 @@ func (t *jolokiaTrait) Configure(e *Environment) (bool, 
error) {
        return e.IntegrationInPhase(v1.IntegrationPhaseInitialization) || 
e.IntegrationInRunningPhases(), nil
 }
 
-func (t *jolokiaTrait) Apply(e *Environment) (err error) {
+func (t *jolokiaTrait) Apply(e *Environment) error {
        if e.IntegrationInPhase(v1.IntegrationPhaseInitialization) {
                // Add the Camel management and Jolokia agent dependencies
                // Also add the Camel JAXB dependency, that's required by Hawtio
diff --git a/pkg/trait/pod.go b/pkg/trait/pod.go
index b139eb81e..b6ea6ed1f 100644
--- a/pkg/trait/pod.go
+++ b/pkg/trait/pod.go
@@ -98,22 +98,24 @@ func (t *podTrait) Apply(e *Environment) error {
        return nil
 }
 
-func (t *podTrait) applyChangesTo(podSpec *corev1.PodSpec, changes v1.PodSpec) 
(patchedPodSpec *corev1.PodSpec, err error) {
+func (t *podTrait) applyChangesTo(podSpec *corev1.PodSpec, changes v1.PodSpec) 
(*corev1.PodSpec, error) {
        patch, err := json.Marshal(changes)
        if err != nil {
-               return
+               return nil, err
        }
 
        sourceJSON, err := json.Marshal(podSpec)
        if err != nil {
-               return
+               return nil, err
        }
 
        patched, err := strategicpatch.StrategicMergePatch(sourceJSON, patch, 
corev1.PodSpec{})
        if err != nil {
-               return
+               return nil, err
        }
 
+       var patchedPodSpec *corev1.PodSpec
        err = json.Unmarshal(patched, &patchedPodSpec)
-       return
+
+       return patchedPodSpec, err
 }
diff --git a/pkg/trait/prometheus.go b/pkg/trait/prometheus.go
index 134b1e62c..445dec5c7 100644
--- a/pkg/trait/prometheus.go
+++ b/pkg/trait/prometheus.go
@@ -53,7 +53,7 @@ func (t *prometheusTrait) Configure(e *Environment) (bool, 
error) {
        return e.IntegrationInPhase(v1.IntegrationPhaseInitialization) || 
e.IntegrationInRunningPhases(), nil
 }
 
-func (t *prometheusTrait) Apply(e *Environment) (err error) {
+func (t *prometheusTrait) Apply(e *Environment) error {
        if e.IntegrationInPhase(v1.IntegrationPhaseInitialization) {
                // Add the Camel Quarkus MP Metrics extension
                util.StringSliceUniqueAdd(&e.Integration.Status.Dependencies, 
"mvn:org.apache.camel.quarkus:camel-quarkus-microprofile-metrics")
diff --git a/pkg/trait/toleration.go b/pkg/trait/toleration.go
index daab0c59c..c8c6a79b9 100644
--- a/pkg/trait/toleration.go
+++ b/pkg/trait/toleration.go
@@ -50,7 +50,7 @@ func (t *tolerationTrait) Configure(e *Environment) (bool, 
error) {
        return e.IntegrationInRunningPhases(), nil
 }
 
-func (t *tolerationTrait) Apply(e *Environment) (err error) {
+func (t *tolerationTrait) Apply(e *Environment) error {
        tolerations, err := kubernetes.NewTolerations(t.Taints)
        if err != nil {
                return err
diff --git a/pkg/trait/trait_types.go b/pkg/trait/trait_types.go
index c38780cb5..04ab4e3a3 100644
--- a/pkg/trait/trait_types.go
+++ b/pkg/trait/trait_types.go
@@ -293,7 +293,8 @@ func (e *Environment) DetermineControllerStrategy() 
(ControllerStrategy, error)
        return defaultStrategy, nil
 }
 
-func (e *Environment) getControllerStrategyChoosers() (res 
[]ControllerStrategySelector) {
+func (e *Environment) getControllerStrategyChoosers() 
[]ControllerStrategySelector {
+       var res []ControllerStrategySelector
        for _, t := range e.ConfiguredTraits {
                if cc, ok := t.(ControllerStrategySelector); ok {
                        res = append(res, cc)
diff --git a/pkg/util/command.go b/pkg/util/command.go
index 196915967..a3de8522d 100644
--- a/pkg/util/command.go
+++ b/pkg/util/command.go
@@ -28,16 +28,16 @@ import (
 
 // RunAndLog starts the provided command, scans its standard and error outputs 
line by line,
 // to feed the provided handlers, and waits until the scans complete and the 
command returns.
-func RunAndLog(ctx context.Context, cmd *exec.Cmd, stdOutF func(string), 
stdErrF func(string)) (err error) {
+func RunAndLog(ctx context.Context, cmd *exec.Cmd, stdOutF func(string), 
stdErrF func(string)) error {
        stdOutF(fmt.Sprintf("Executed command: %s", cmd.String()))
 
        stdOut, err := cmd.StdoutPipe()
        if err != nil {
-               return
+               return err
        }
        stdErr, err := cmd.StderrPipe()
        if err != nil {
-               return
+               return err
        }
        err = cmd.Start()
        if err != nil {
@@ -49,7 +49,7 @@ func RunAndLog(ctx context.Context, cmd *exec.Cmd, stdOutF 
func(string), stdErrF
                for scanErr.Scan() {
                        stdOutF(scanErr.Text())
                }
-               return
+               return err
        }
        g, _ := errgroup.WithContext(ctx)
        g.Go(func() error {
@@ -66,13 +66,12 @@ func RunAndLog(ctx context.Context, cmd *exec.Cmd, stdOutF 
func(string), stdErrF
                }
                return nil
        })
-       err = g.Wait()
-       if err != nil {
-               return
+       if err = g.Wait(); err != nil {
+               return err
        }
-       err = cmd.Wait()
-       if err != nil {
-               return
+       if err = cmd.Wait(); err != nil {
+               return err
        }
-       return
+
+       return nil
 }
diff --git a/pkg/util/kubernetes/portforward.go 
b/pkg/util/kubernetes/portforward.go
index 1648fa5be..54ec4d33a 100644
--- a/pkg/util/kubernetes/portforward.go
+++ b/pkg/util/kubernetes/portforward.go
@@ -118,7 +118,7 @@ func PortForward(ctx context.Context, c client.Client, ns, 
labelSelector string,
        }
 }
 
-func portFowardPod(ctx context.Context, config *restclient.Config, ns, pod 
string, localPort, remotePort uint, stdOut, stdErr io.Writer) (host string, err 
error) {
+func portFowardPod(ctx context.Context, config *restclient.Config, ns, pod 
string, localPort, remotePort uint, stdOut, stdErr io.Writer) (string, error) {
        c, err := corev1client.NewForConfig(config)
        if err != nil {
                return "", err
diff --git a/pkg/util/maven/maven_log.go b/pkg/util/maven/maven_log.go
index 0ed0c84f9..1c1c4ab02 100644
--- a/pkg/util/maven/maven_log.go
+++ b/pkg/util/maven/maven_log.go
@@ -59,9 +59,10 @@ func mavenLogHandler(s string) {
        }
 }
 
-func parseLog(line string) (l mavenLog, err error) {
-       err = json.Unmarshal([]byte(line), &l)
-       return
+func parseLog(line string) (mavenLog, error) {
+       var l mavenLog
+       err := json.Unmarshal([]byte(line), &l)
+       return l, err
 }
 
 func normalizeLog(mavenLog mavenLog) {
diff --git a/pkg/util/maven/maven_repositories.go 
b/pkg/util/maven/maven_repositories.go
index 710dbada5..e4ee39a2b 100644
--- a/pkg/util/maven/maven_repositories.go
+++ b/pkg/util/maven/maven_repositories.go
@@ -36,11 +36,12 @@ func (o defaultRepositories) apply(settings *Settings) 
error {
        return nil
 }
 
-func defaultMavenRepositories() (repositories []v1.Repository) {
+func defaultMavenRepositories() []v1.Repository {
+       var repositories []v1.Repository
        for _, repository := range strings.Split(DefaultMavenRepositories, ",") 
{
                repositories = append(repositories, NewRepository(repository))
        }
-       return
+       return repositories
 }
 
 func Repositories(repositories ...string) SettingsOption {
diff --git a/pkg/util/modeline/parser.go b/pkg/util/modeline/parser.go
index ab1eab580..29924eeba 100644
--- a/pkg/util/modeline/parser.go
+++ b/pkg/util/modeline/parser.go
@@ -33,11 +33,12 @@ var (
        xmlModelineRegexp    = 
regexp.MustCompile(`^.*<!--\s*camel-k\s*:\s*([^\s]+[^>]*)-->.*$`)
 )
 
-func Parse(name, content string) (res []Option, err error) {
+func Parse(name, content string) ([]Option, error) {
        lang := inferLanguage(name)
        if lang == "" {
                return nil, fmt.Errorf("unsupported file type %s", name)
        }
+       var res []Option
        scanner := bufio.NewScanner(strings.NewReader(content))
        for scanner.Scan() {
                res = append(res, getModelineOptions(scanner.Text(), lang)...)
@@ -45,11 +46,12 @@ func Parse(name, content string) (res []Option, err error) {
        return res, scanner.Err()
 }
 
-func getModelineOptions(line string, lang v1.Language) (res []Option) {
+func getModelineOptions(line string, lang v1.Language) []Option {
        reg := modelineRegexp(lang)
        if !reg.MatchString(line) {
                return nil
        }
+       var res []Option
        strs := reg.FindStringSubmatch(line)
        if len(strs) == 2 {
                tokens, _ := shellwords.Parse(strs[1])
diff --git a/pkg/util/resource/config.go b/pkg/util/resource/config.go
index 83d2b145e..6bfa5be2b 100644
--- a/pkg/util/resource/config.go
+++ b/pkg/util/resource/config.go
@@ -120,9 +120,9 @@ func newConfig(storageType StorageType, contentType 
ContentType, value string) *
        }
 }
 
-func parseResourceValue(storageType StorageType, value string) (resource 
string, maybeKey string, maybeDestinationPath string) {
+func parseResourceValue(storageType StorageType, value string) (string, 
string, string) {
        if storageType == StorageTypeFile {
-               resource, maybeDestinationPath = ParseFileValue(value)
+               resource, maybeDestinationPath := ParseFileValue(value)
                return resource, "", maybeDestinationPath
        }
 
@@ -131,7 +131,7 @@ func parseResourceValue(storageType StorageType, value 
string) (resource string,
 
 // ParseFileValue will parse a file resource/config option to return the local 
path and the
 // destination path expected.
-func ParseFileValue(value string) (localPath string, maybeDestinationPath 
string) {
+func ParseFileValue(value string) (string, string) {
        split := strings.SplitN(value, "@", 2)
        if len(split) == 2 {
                return split[0], split[1]
@@ -140,7 +140,7 @@ func ParseFileValue(value string) (localPath string, 
maybeDestinationPath string
        return value, ""
 }
 
-func parseCMOrSecretValue(value string) (resource string, maybeKey string, 
maybeDestinationPath string) {
+func parseCMOrSecretValue(value string) (string, string, string) {
        if !validResourceRegexp.MatchString(value) {
                return value, "", ""
        }
diff --git a/pkg/util/source/inspector_kamelet.go 
b/pkg/util/source/inspector_kamelet.go
index 8ac31f839..a9a155efa 100644
--- a/pkg/util/source/inspector_kamelet.go
+++ b/pkg/util/source/inspector_kamelet.go
@@ -23,17 +23,18 @@ import (
 
 var kameletNameRegexp = 
regexp.MustCompile("kamelet:(?://)?([a-z0-9-.]+(/[a-z0-9-.]+)?)(?:$|[^a-z0-9-.].*)")
 
-func ExtractKamelets(uris []string) (kamelets []string) {
+func ExtractKamelets(uris []string) []string {
+       var kamelets []string
        for _, uri := range uris {
                kamelet := ExtractKamelet(uri)
                if kamelet != "" {
                        kamelets = append(kamelets, kamelet)
                }
        }
-       return
+       return kamelets
 }
 
-func ExtractKamelet(uri string) (kamelet string) {
+func ExtractKamelet(uri string) string {
        matches := kameletNameRegexp.FindStringSubmatch(uri)
        if len(matches) > 1 {
                return matches[1]
diff --git a/pkg/util/test/client.go b/pkg/util/test/client.go
index 7086e05df..e302fca9a 100644
--- a/pkg/util/test/client.go
+++ b/pkg/util/test/client.go
@@ -64,7 +64,7 @@ func NewFakeClient(initObjs ...runtime.Object) 
(client.Client, error) {
        })...)
        replicasCount := make(map[string]int32)
        fakescaleclient := fakescale.FakeScaleClient{}
-       fakescaleclient.AddReactor("update", "*", func(rawAction 
testing.Action) (handled bool, ret runtime.Object, err error) {
+       fakescaleclient.AddReactor("update", "*", func(rawAction 
testing.Action) (bool, runtime.Object, error) {
                action := rawAction.(testing.UpdateAction)       // nolint: 
forcetypeassert
                obj := action.GetObject().(*autoscalingv1.Scale) // nolint: 
forcetypeassert
                replicas := obj.Spec.Replicas
@@ -80,7 +80,7 @@ func NewFakeClient(initObjs ...runtime.Object) 
(client.Client, error) {
                        },
                }, nil
        })
-       fakescaleclient.AddReactor("get", "*", func(rawAction testing.Action) 
(handled bool, ret runtime.Object, err error) {
+       fakescaleclient.AddReactor("get", "*", func(rawAction testing.Action) 
(bool, runtime.Object, error) {
                action := rawAction.(testing.GetAction) // nolint: 
forcetypeassert
                key := fmt.Sprintf("%s:%s:%s/%s", action.GetResource().Group, 
action.GetResource().Resource, action.GetNamespace(), action.GetName())
                obj := &autoscalingv1.Scale{
@@ -103,7 +103,8 @@ func NewFakeClient(initObjs ...runtime.Object) 
(client.Client, error) {
        }, nil
 }
 
-func filterObjects(scheme *runtime.Scheme, input []runtime.Object, filter 
func(gvk schema.GroupVersionKind) bool) (res []runtime.Object) {
+func filterObjects(scheme *runtime.Scheme, input []runtime.Object, filter 
func(gvk schema.GroupVersionKind) bool) []runtime.Object {
+       var res []runtime.Object
        for _, obj := range input {
                kinds, _, _ := scheme.ObjectKinds(obj)
                for _, k := range kinds {
diff --git a/pkg/util/test/cmd.go b/pkg/util/test/cmd.go
index 7d7f00345..cb8f1f150 100644
--- a/pkg/util/test/cmd.go
+++ b/pkg/util/test/cmd.go
@@ -29,18 +29,18 @@ func ArbitraryArgs(cmd *cobra.Command, args []string) error 
{
        return nil
 }
 
-func ExecuteCommand(root *cobra.Command, args ...string) (output string, err 
error) {
-       _, output, err = ExecuteCommandC(root, args...)
+func ExecuteCommand(root *cobra.Command, args ...string) (string, error) {
+       _, output, err := ExecuteCommandC(root, args...)
        return output, err
 }
 
-func ExecuteCommandC(root *cobra.Command, args ...string) (c *cobra.Command, 
output string, err error) {
+func ExecuteCommandC(root *cobra.Command, args ...string) (*cobra.Command, 
string, error) {
        buf := new(bytes.Buffer)
        root.SetOut(buf)
        root.SetErr(buf)
        root.SetArgs(args)
 
-       c, err = root.ExecuteC()
+       c, err := root.ExecuteC()
 
        return c, buf.String(), err
 }
diff --git a/pkg/util/util.go b/pkg/util/util.go
index 5143c6830..55e688fd7 100644
--- a/pkg/util/util.go
+++ b/pkg/util/util.go
@@ -241,20 +241,20 @@ func EncodeXML(content interface{}) ([]byte, error) {
        return w.Bytes(), nil
 }
 
-func CopyFile(src, dst string) (nBytes int64, err error) {
+func CopyFile(src, dst string) (int64, error) {
        stat, err := os.Stat(src)
        if err != nil {
-               return
+               return 0, err
        }
 
        if !stat.Mode().IsRegular() {
                err = fmt.Errorf("%s is not a regular file", src)
-               return
+               return 0, err
        }
 
        source, err := Open(src)
        if err != nil {
-               return
+               return 0, err
        }
 
        defer func() {
@@ -265,23 +265,22 @@ func CopyFile(src, dst string) (nBytes int64, err error) {
        // in the container may not be the same as the one owning the files
        //
        // #nosec G301
-       err = os.MkdirAll(path.Dir(dst), 0o755)
-       if err != nil {
-               return
+       if err = os.MkdirAll(path.Dir(dst), 0o755); err != nil {
+               return 0, err
        }
 
        destination, err := OpenFile(dst, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 
stat.Mode())
        if err != nil {
-               return
+               return 0, err
        }
 
        defer func() {
                err = Close(err, destination)
        }()
 
-       nBytes, err = io.Copy(destination, source)
+       nBytes, err := io.Copy(destination, source)
 
-       return
+       return nBytes, err
 }
 
 func WriteFileWithBytesMarshallerContent(basePath string, filePath string, 
content BytesMarshaller) error {
@@ -342,22 +341,22 @@ func DirectoryExists(directory string) (bool, error) {
        return info.IsDir(), nil
 }
 
-func DirectoryEmpty(directory string) (ok bool, err error) {
+func DirectoryEmpty(directory string) (bool, error) {
        f, err := Open(directory)
        if err != nil {
-               return
+               return false, err
        }
 
        defer func() {
                err = Close(err, f)
        }()
 
-       _, err = f.Readdirnames(1)
-       if errors.Is(err, io.EOF) {
+       ok := false
+       if _, err = f.Readdirnames(1); errors.Is(err, io.EOF) {
                ok = true
        }
 
-       return
+       return ok, err
 }
 
 func CreateDirectory(directory string) error {

Reply via email to