Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions internal/pkg/agent/application/upgrade/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ func cleanNonMatchingVersionsFromDownloads(log *logger.Logger, version string) e
log.Debugw("Cleaning up non-matching downloaded versions", "version", version, "downloads.path", downloadsPath)

files, err := os.ReadDir(downloadsPath)
if os.IsNotExist(err) {
// nothing to clean up
return nil
}

if err != nil {
return fmt.Errorf("unable to read directory %q: %w", paths.Downloads(), err)
}
Expand Down
7 changes: 7 additions & 0 deletions internal/pkg/agent/application/upgrade/step_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ package upgrade

import (
"context"
"fmt"
"os"
"strings"

"go.elastic.co/apm"

"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/artifact"
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/artifact/download"
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/artifact/download/composed"
Expand Down Expand Up @@ -54,6 +57,10 @@ func (u *Upgrader) downloadArtifact(ctx context.Context, version, sourceURI stri
return "", errors.New(err, "initiating fetcher")
}

if err := os.MkdirAll(paths.Downloads(), 0755); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: do we really need 0755? why not 0750 ?

return "", errors.New(err, fmt.Sprintf("failed to create download directory at %s", paths.Downloads()))
}

path, err := fetcher.Download(ctx, agentArtifact, version)
if err != nil {
return "", errors.New(err, "failed upgrade of agent binary")
Expand Down