Skip to content

Commit

Permalink
writes a package summary file
Browse files Browse the repository at this point in the history
  • Loading branch information
taukakao authored and mirkobrombin committed Aug 1, 2024
1 parent 734e9dd commit 34a215a
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
70 changes: 70 additions & 0 deletions core/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,76 @@ func (p *PackageManager) GetFinalCmd(operation ABSystemOperation) string {
return cmd
}

func (p *PackageManager) getSummary() (string, error) {
if p.CheckStatus() != nil {
return "", nil
}

addPkgs, err := p.GetAddPackages()
if err != nil {
if errors.Is(err, &os.PathError{}) {
addPkgs = []string{}
} else {
return "", err
}
}
removePkgs, err := p.GetRemovePackages()
if err != nil {
if errors.Is(err, &os.PathError{}) {
removePkgs = []string{}
} else {
return "", err
}
}

// GetPackages returns slices with one empty element if there are no packages
if len(addPkgs) == 1 && addPkgs[0] == "" {
addPkgs = []string{}
}
if len(removePkgs) == 1 && removePkgs[0] == "" {
removePkgs = []string{}
}

summary := ""

for _, pkg := range addPkgs {
summary += "+ " + pkg + "\n"
}
for _, pkg := range removePkgs {
summary += "- " + pkg + "\n"
}

return summary, nil
}

// WriteSummaryToFile writes added and removed packages to summaryFilePath
//
// added packages get the + prefix, while removed packages get the - prefix
func (p *PackageManager) WriteSummaryToFile(summaryFilePath string) error {
summary, err := p.getSummary()
if err != nil {
return err
}
if summary == "" {
return nil
}
summaryFile, err := os.Create(summaryFilePath)
if err != nil {
return err
}
defer summaryFile.Close()
err = summaryFile.Chmod(0o644)
if err != nil {
return err
}
_, err = summaryFile.WriteString(summary)
if err != nil {
return err
}

return nil
}

// assertPkgMngApiSetUp checks whether the repo API is properly configured.
// If a configuration exists but is malformed, returns an error.
func assertPkgMngApiSetUp() (bool, error) {
Expand Down
6 changes: 6 additions & 0 deletions core/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,12 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation) error {
return err
}

err = pkgM.WriteSummaryToFile(filepath.Join(systemNew, "/usr/share/abroot/package-summary"))
if err != nil {
PrintVerboseErr("ABSystem.RunOperation", 5.26, err)
return err
}

// from this point on, it is not possible to stop the upgrade
// so we remove the stage file. Note that interrupting the upgrade
// from this point on will not leave the system in an inconsistent
Expand Down

0 comments on commit 34a215a

Please sign in to comment.