Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick #24343 to 7.12: Fix windows installer during enroll #24389

Merged
merged 1 commit into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions x-pack/elastic-agent/CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
- Fix reloading of log level for services {pull}[24055]24055
- Fix: Successfully installed and enrolled agent running standalone{pull}[24128]24128
- Make installer atomic on windows {pull}[24253]24253
- Fix windows installer during enroll {pull}[24343]24343

==== New features

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ func (i *Installer) Install(ctx context.Context, spec program.Spec, version, ins
os.RemoveAll(tempInstallDir)
}

// on windows rename is not atomic, let's force it to flush the cache
defer func() {
if runtime.GOOS == "windows" {
if f, err := os.OpenFile(installDir, os.O_RDWR, 0777); err == nil {
f.Sync()
f.Close()
}

if f, err := os.OpenFile(tempInstallDir, os.O_RDWR, 0777); err == nil {
f.Sync()
f.Close()
}
}
}()

if err := i.installer.Install(ctx, spec, version, tempInstallDir); err != nil {
// cleanup unfinished install
if rerr := os.RemoveAll(tempInstallDir); rerr != nil {
Expand All @@ -70,12 +85,5 @@ func (i *Installer) Install(ctx context.Context, spec program.Spec, version, ins
return err
}

// on windows rename is not atomic, let's force it to flush the cache
if runtime.GOOS == "windows" {
if f, err := os.OpenFile(installDir, os.O_SYNC|os.O_RDWR, 0755); err == nil {
f.Sync()
}
}

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (i *Installer) Install(ctx context.Context, spec program.Spec, version, ins
return nil
}

func (i *Installer) unzip(ctx context.Context, artifactPath string) error {
func (i *Installer) unzip(_ context.Context, artifactPath string) error {
r, err := zip.OpenReader(artifactPath)
if err != nil {
return err
Expand Down Expand Up @@ -120,11 +120,6 @@ func (i *Installer) unzip(ctx context.Context, artifactPath string) error {
}

for _, f := range r.File {
// if we were cancelled in between
if err := ctx.Err(); err != nil {
return err
}

if err := unpackFile(f); err != nil {
return err
}
Expand Down