Skip to content

Commit

Permalink
[Ingest-Manager] Fix windows installer during enroll (#24343) (#24388)
Browse files Browse the repository at this point in the history
[Ingest-Manager] Fix windows installer during enroll (#24343)
  • Loading branch information
michalpristas authored Mar 9, 2021
1 parent 29b5d11 commit 58a8a33
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
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
- Fix failing installation on windows 7 {pull}[24387]24387
- Fix capabilities resolution in inspect command {pull}[24346]24346

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

0 comments on commit 58a8a33

Please sign in to comment.