Skip to content

Commit

Permalink
this makes sure binaries are not deleted (#2025)
Browse files Browse the repository at this point in the history
As per the code comments this makes sure
that binaries (and libs) don't get deleted from the system
  • Loading branch information
muhamadazmy authored Aug 22, 2023
1 parent d96dff4 commit fa583e0
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions pkg/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,12 @@ func (u *Upgrader) ensureRestarted(service ...string) error {

// UninstallBinary from a single flist.
func (u *Upgrader) UninstallBinary(flist FListInfo) error {
return u.uninstall(flist)
// we never delete those files from the system
// since there is no `package manager` for zos (yet)
// deleting the files from the flist blindly can cause
// issues if some deleted files were shared between
// multiple packages.
return u.uninstall(flist, false)
}

// upgradeSelf will try to check if the flist has
Expand Down Expand Up @@ -284,7 +289,9 @@ func (u *Upgrader) upgradeSelf(store meta.Walker) error {
return ErrRestartNeeded
}

func (u *Upgrader) uninstall(flist FListInfo) error {
// uninstall a package, if del is true, also delete the files in that package
// from the system filesystem
func (u *Upgrader) uninstall(flist FListInfo, del bool) error {
files, err := flist.Files()
if err != nil {
return errors.Wrapf(err, "failed to get list of current installed files for '%s'", flist.Absolute())
Expand Down Expand Up @@ -326,6 +333,10 @@ func (u *Upgrader) uninstall(flist FListInfo) error {
}
}

if !del {
return nil
}

// now delete ALL files, ignore what doesn't delete
for _, file := range files {
stat, err := os.Stat(file.Path)
Expand Down Expand Up @@ -367,7 +378,7 @@ func (u *Upgrader) applyUpgrade(from, to FullFListInfo) error {
return err
}

if err := u.uninstall(from.FListInfo); err != nil {
if err := u.uninstall(from.FListInfo, true); err != nil {
log.Error().Err(err).Msg("failed to uninstall current flist. Upgraded anyway")
}

Expand Down

0 comments on commit fa583e0

Please sign in to comment.