-
Notifications
You must be signed in to change notification settings - Fork 155
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
Use package manifests for upgrade #4174
Changes from 7 commits
12510ff
3d8a1ce
097d0ad
d34895c
cd2e9de
bf2e849
ee9979c
9f2a4cc
9945a14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,21 +32,26 @@ func ChangeSymlink(ctx context.Context, log *logger.Logger, targetHash string) e | |
// paths.BinaryPath properly derives the binary directory depending on the platform. The path to the binary for macOS is inside of the app bundle. | ||
newPath := paths.BinaryPath(filepath.Join(paths.Top(), "data", hashedDir), agentName) | ||
|
||
return changeSymlinkInternal(log, symlinkPath, newPath) | ||
} | ||
|
||
func changeSymlinkInternal(log *logger.Logger, symlinkPath, newTarget string) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: why not just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function replaces At this point in time I still had references to the old ChangeSymlink that I wanted to remove so I thought of giving changeSymlinkInternal a very specific name ;) |
||
|
||
// handle windows suffixes | ||
if runtime.GOOS == windows { | ||
symlinkPath += exe | ||
newPath += exe | ||
newTarget += exe | ||
} | ||
|
||
prevNewPath := prevSymlinkPath() | ||
log.Infow("Changing symlink", "symlink_path", symlinkPath, "new_path", newPath, "prev_path", prevNewPath) | ||
log.Infow("Changing symlink", "symlink_path", symlinkPath, "new_path", newTarget, "prev_path", prevNewPath) | ||
|
||
// remove symlink to avoid upgrade failures | ||
if err := os.Remove(prevNewPath); !os.IsNotExist(err) { | ||
return err | ||
} | ||
|
||
if err := os.Symlink(newPath, prevNewPath); err != nil { | ||
if err := os.Symlink(newTarget, prevNewPath); err != nil { | ||
return errors.New(err, errors.TypeFilesystem, "failed to update agent symlink") | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you extract this logic into its own function, you could write a unit test with a couple of test cases around it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are unit tests added in #4176 where the cleanup and rollback were fixed https://github.com/elastic/elastic-agent/pull/4176/files/bf2e849b16f8852a59593e45b8ada9095e190ad1..b17c7132e2b6cd2ff157835379c833435f325fc4#diff-cc4058ffab0db853a72dc782e00a1a7c3c7b7314175bec4538b1f32e69332c66