Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,8 @@ func (i *Installer) Install(ctx context.Context, spec program.Spec, version, ins
// 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()
}
syncDir(installDir)
syncDir(tempInstallDir)
}
}()

Expand All @@ -87,3 +80,10 @@ func (i *Installer) Install(ctx context.Context, spec program.Spec, version, ins

return nil
}

func syncDir(dir string) {
if f, err := os.OpenFile(dir, os.O_RDWR, 0777); err == nil {
f.Sync()
f.Close()
}
}
11 changes: 11 additions & 0 deletions x-pack/elastic-agent/pkg/artifact/install/zip/zip_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,13 @@ func (i *Installer) Install(ctx context.Context, spec program.Spec, version, ins
// if root directory is not the same as desired directory rename
// e.g contains `-windows-` or `-SNAPSHOT-`
if rootDir != installDir {
defer syncDir(rootDir)
defer syncDir(installDir)

if err := os.Rename(rootDir, installDir); err != nil {
return errors.New(err, errors.TypeFilesystem, errors.M(errors.MetaKeyPath, installDir))
}

}

return nil
Expand Down Expand Up @@ -155,3 +159,10 @@ func (i *Installer) getRootDir(zipPath string) (dir string, err error) {

return rootDir, nil
}

func syncDir(dir string) {
if f, err := os.OpenFile(dir, os.O_RDWR, 0777); err == nil {
f.Sync()
f.Close()
}
}