diff --git a/cmd/root.go b/cmd/root.go index d16e675..569fe29 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -73,5 +73,6 @@ func init() { isTerminal := term.IsTerminal(int(os.Stdout.Fd())) rootCmd.Flags().BoolP("no-progress", "p", !isTerminal, "Do not show progress bars") rootCmd.Flags().BoolP("hw-check", "c", false, "Run hardware check before running updates") - rootCmd.Flags().BoolP("dry-run", "n", false, "Do a dry run (used for testing)") + rootCmd.Flags().BoolP("dry-run", "n", false, "Do a dry run") + rootCmd.Flags().BoolP("verbose", "v", false, "Display command outputs after run") } diff --git a/cmd/update.go b/cmd/update.go index 0f48a28..bdff95e 100644 --- a/cmd/update.go +++ b/cmd/update.go @@ -3,38 +3,21 @@ package cmd import ( "fmt" "log" - "os/exec" - "strings" "github.com/jedib0t/go-pretty/v6/progress" "github.com/spf13/cobra" "github.com/ublue-os/uupd/checks" "github.com/ublue-os/uupd/drv" "github.com/ublue-os/uupd/lib" + "gopkg.in/yaml.v3" ) -type Failure struct { - Err error - Output string -} - func Update(cmd *cobra.Command, args []string) { lock, err := lib.AcquireLock() if err != nil { log.Fatalf("%v, is uupd already running?", err) } - systemDriver, err := drv.GetSystemUpdateDriver() - if err != nil { - log.Fatalf("Failed to get system update driver: %v", err) - } - outdated, err := systemDriver.ImageOutdated() - if err != nil { - log.Fatalf("Unable to determine if image is outdated: %v", err) - } - if outdated { - lib.Notify("System Warning", "There hasn't been an update in over a month. Consider rebooting or running updates manually") - log.Printf("There hasn't been an update in over a month. Consider rebooting or running updates manually") - } + defer lib.ReleaseLock(lock) hwCheck, err := cmd.Flags().GetBool("hw-check") if err != nil { @@ -44,6 +27,10 @@ func Update(cmd *cobra.Command, args []string) { if err != nil { log.Fatalf("Failed to get dry-run flag: %v", err) } + verboseRun, err := cmd.Flags().GetBool("verbose") + if err != nil { + log.Fatalf("Failed to get verbose flag: %v", err) + } if hwCheck { err := checks.RunHwChecks() @@ -58,153 +45,124 @@ func Update(cmd *cobra.Command, args []string) { log.Fatalf("Failed to list users") } - // Check if system update is available - log.Printf("Checking for system updates (%s)", systemDriver.Name) - updateAvailable, err := systemDriver.UpdateAvailable() - // ignore error on dry run - if err != nil && !dryRun { - log.Fatalf("Failed to check for image updates: %v", err) + systemUpdater, err := drv.SystemUpdater{}.New(dryRun) + if err != nil { + systemUpdater.Config.Enabled = false + } else { + systemUpdater.Check() + } + + brewUpdater, err := drv.BrewUpdater{}.New(dryRun) + if err != nil { + brewUpdater.Config.Enabled = false } - log.Printf("System updates available: %t (%s)", updateAvailable, systemDriver.Name) - // don't update system if there's a dry run - updateAvailable = updateAvailable && !dryRun - systemUpdate := 0 - if updateAvailable { - systemUpdate = 1 + + flatpakUpdater, err := drv.FlatpakUpdater{}.New(dryRun) + if err != nil { + flatpakUpdater.Config.Enabled = false } + flatpakUpdater.SetUsers(users) - // Check if brew is installed - brewUid, brewErr := drv.GetBrewUID() - brewUpdate := 0 - if brewErr == nil { - brewUpdate = 1 + distroboxUpdater, err := drv.DistroboxUpdater{}.New(dryRun) + if err != nil { + distroboxUpdater.Config.Enabled = false } + distroboxUpdater.SetUsers(users) - totalSteps := brewUpdate + systemUpdate + 1 + len(users) + 1 + len(users) // system + Brew + Flatpak (users + root) + Distrobox (users + root) + totalSteps := brewUpdater.Steps() + systemUpdater.Steps() + flatpakUpdater.Steps() + distroboxUpdater.Steps() pw := lib.NewProgressWriter() pw.SetNumTrackersExpected(1) pw.SetAutoStop(false) - noProgress, err := cmd.Flags().GetBool("no-progress") + progressEnabled, err := cmd.Flags().GetBool("no-progress") if err != nil { log.Fatalf("Failed to get no-progress flag: %v", err) } + // Move this to its actual boolean value (~no-progress) + progressEnabled = !progressEnabled - if !noProgress { + if progressEnabled { go pw.Render() } - // move this to its actual boolean value (progress bar = false) - noProgress = !noProgress + // -1 because 0 index tracker := lib.NewIncrementTracker(&progress.Tracker{Message: "Updating", Units: progress.UnitsDefault, Total: int64(totalSteps - 1)}, totalSteps-1) pw.AppendTracker(tracker.Tracker) - failures := make(map[string]Failure) + var trackerConfig = &drv.TrackerConfiguration{ + Tracker: tracker, + Writer: &pw, + Progress: progressEnabled, + } + flatpakUpdater.Tracker = trackerConfig + distroboxUpdater.Tracker = trackerConfig - if updateAvailable { - lib.ChangeTrackerMessageFancy(pw, tracker, noProgress, "Updating System") - out, err := systemDriver.Update() - if err != nil { - failures[systemDriver.Name] = Failure{ - err, - string(out), - } - tracker.IncrementSectionError() - } else { - tracker.IncrementSection() - } + var outputs = []drv.CommandOutput{} + + if systemUpdater.Outdated { + lib.Notify("System Warning", "There hasn't been an update in over a month. Consider rebooting or running updates manually") + log.Printf("There hasn't been an update in over a month. Consider rebooting or running updates manually") } - if brewUpdate == 1 { - lib.ChangeTrackerMessageFancy(pw, tracker, noProgress, "Updating CLI apps (Brew)") - out, err := drv.BrewUpdate(brewUid) - if err != nil { - failures["Brew"] = Failure{ - err, - string(out), - } - tracker.IncrementSectionError() - } else { - tracker.IncrementSection() - } + if systemUpdater.Config.Enabled { + lib.ChangeTrackerMessageFancy(pw, tracker, progressEnabled, fmt.Sprintf("Updating %s (%s)", systemUpdater.Config.Description, systemUpdater.Config.Title)) + out, err := systemUpdater.Update() + outputs = append(outputs, *out...) + tracker.IncrementSection(err) } - // Run flatpak updates - lib.ChangeTrackerMessageFancy(pw, tracker, noProgress, "Updating System Apps (Flatpak)") - flatpakCmd := exec.Command("/usr/bin/flatpak", "update", "-y") - out, err := flatpakCmd.CombinedOutput() - if err != nil { - failures["Flatpak"] = Failure{ - err, - string(out), - } - tracker.IncrementSectionError() - } else { - tracker.IncrementSection() + if brewUpdater.Config.Enabled { + lib.ChangeTrackerMessageFancy(pw, tracker, progressEnabled, fmt.Sprintf("Updating %s (%s)", brewUpdater.Config.Description, brewUpdater.Config.Title)) + out, err := brewUpdater.Update() + outputs = append(outputs, *out...) + tracker.IncrementSection(err) } - for _, user := range users { - lib.ChangeTrackerMessageFancy(pw, tracker, noProgress, fmt.Sprintf("Updating Apps for User: %s (Flatpak)", user.Name)) - out, err := lib.RunUID(user.UID, []string{"/usr/bin/flatpak", "update", "-y"}, nil) - if err != nil { - failures[fmt.Sprintf("Flatpak User: %s", user.Name)] = Failure{ - err, - string(out), - } - tracker.IncrementSectionError() - } else { - tracker.IncrementSection() - } + + if flatpakUpdater.Config.Enabled { + out, err := flatpakUpdater.Update() + outputs = append(outputs, *out...) + tracker.IncrementSection(err) } - // Run distrobox updates - lib.ChangeTrackerMessageFancy(pw, tracker, noProgress, "Updating System Distroboxes") - // distrobox doesn't support sudo, run with systemd-run - out, err = lib.RunUID(0, []string{"/usr/bin/distrobox", "upgrade", "-a"}, nil) - if err != nil { - failures["Distrobox"] = Failure{ - err, - string(out), - } - tracker.IncrementSectionError() - } else { - tracker.IncrementSection() + if distroboxUpdater.Config.Enabled { + out, err := distroboxUpdater.Update() + outputs = append(outputs, *out...) + tracker.IncrementSection(err) } - for _, user := range users { - lib.ChangeTrackerMessageFancy(pw, tracker, noProgress, fmt.Sprintf("Updating Distroboxes for User: %s", user.Name)) - out, err := lib.RunUID(user.UID, []string{"/usr/bin/distrobox", "upgrade", "-a"}, nil) + + pw.Stop() + + if verboseRun { + log.Println("Verbose run requested") + + b, err := yaml.Marshal(outputs) if err != nil { - failures[fmt.Sprintf("Distrobox User: %s", user.Name)] = Failure{ - err, - string(out), - } - tracker.IncrementSectionError() - } else { - tracker.IncrementSection() + log.Fatalf("Failure!") + return } + log.Printf("%s", string(b)) + return } - pw.Stop() - if len(failures) > 0 { - failedSystemsList := make([]string, 0, len(failures)) - for systemName := range failures { - failedSystemsList = append(failedSystemsList, systemName) + var failures = []drv.CommandOutput{} + for _, output := range outputs { + if output.Failure { + failures = append(failures, output) } - failedSystemsStr := strings.Join(failedSystemsList, ", ") - lib.Notify("Updates failed", fmt.Sprintf("uupd failed to update: %s, consider seeing logs with `journalctl -exu uupd.service`", failedSystemsStr)) - log.Printf("Updates Completed with Failures:") - for name, fail := range failures { - indentedOutput := "\t | " - lines := strings.Split(fail.Output, "\n") - for i, line := range lines { - if i > 0 { - indentedOutput += "\n\t | " - } - indentedOutput += line - } - log.Printf("---> %s \n\t | Failure error: %v \n\t | Command Output: \n%s", name, fail.Err, indentedOutput) + } + + if len(failures) > 0 { + log.Println("Exited with failed updates.\nFailures found:") + + b, err := yaml.Marshal(failures) + if err != nil { + log.Fatalf("Failure!") + return } + log.Printf("%s", string(b)) + return } + log.Printf("Updates Completed") - lib.ReleaseLock(lock) } diff --git a/drv/brew.go b/drv/brew.go index 3cf02b3..e281506 100644 --- a/drv/brew.go +++ b/drv/brew.go @@ -7,44 +7,95 @@ import ( "syscall" ) -var ( - brewPrefix = "/home/linuxbrew/.linuxbrew" - brewCellar = fmt.Sprintf("%s/Cellar", brewPrefix) - brewRepo = fmt.Sprintf("%s/Homebrew", brewPrefix) - brewPath = fmt.Sprintf("%s/bin/brew", brewPrefix) -) - -func GetBrewUID() (int, error) { - inf, err := os.Stat(brewPrefix) +func (up BrewUpdater) GetBrewUID() (int, error) { + inf, err := os.Stat(up.Environment["HOMEBREW_PREFIX"]) if err != nil { return -1, err } if !inf.IsDir() { - return -1, fmt.Errorf("Brew prefix: %v, is not a dir.", brewPrefix) + return -1, fmt.Errorf("Brew prefix: %v, is not a dir.", up.Environment["HOMEBREW_PREFIX"]) } stat, ok := inf.Sys().(*syscall.Stat_t) if !ok { - return -1, fmt.Errorf("Unable to retriev UID info for %v", brewPrefix) + return -1, fmt.Errorf("Unable to retriev UID info for %v", up.Environment["HOMEBREW_PREFIX"]) } return int(stat.Uid), nil } -func BrewUpdate(uid int) ([]byte, error) { - env := map[string]string{ +func (up BrewUpdater) Steps() int { + if up.Config.Enabled { + return 1 + } + return 0 +} + +func (up BrewUpdater) Check() (*[]CommandOutput, error) { + // TODO: implement + return nil, nil +} + +func (up BrewUpdater) Update() (*[]CommandOutput, error) { + var final_output = []CommandOutput{} + + if up.Config.DryRun { + return &final_output, nil + } + + out, err := lib.RunUID(up.BaseUser, []string{up.Environment["HOMEBREW_PATH"], "update"}, up.Environment) + tmpout := CommandOutput{}.New(out, err) + if err != nil { + tmpout.SetFailureContext("Brew update") + final_output = append(final_output, *tmpout) + return &final_output, err + } + + out, err = lib.RunUID(up.BaseUser, []string{up.Environment["HOMEBREW_PATH"], "upgrade"}, up.Environment) + tmpout = CommandOutput{}.New(out, err) + if err != nil { + tmpout.SetFailureContext("Brew upgrade") + } + final_output = append(final_output, *tmpout) + return &final_output, err +} + +type BrewUpdater struct { + Config DriverConfiguration + BaseUser int + Environment map[string]string +} + +func (up BrewUpdater) New(dryrun bool) (BrewUpdater, error) { + // TODO: add support for actual environment variables to override this + var ( + brewPrefix = "/home/linuxbrew/.linuxbrew" + brewCellar = fmt.Sprintf("%s/Cellar", brewPrefix) + brewRepo = fmt.Sprintf("%s/Homebrew", brewPrefix) + brewPath = fmt.Sprintf("%s/bin/brew", brewPrefix) + ) + up.Environment = map[string]string{ "HOMEBREW_PREFIX": brewPrefix, "HOMEBREW_REPOSITORY": brewRepo, "HOMEBREW_CELLAR": brewCellar, + "HOMEBREW_PATH": brewPath, } - out, err := lib.RunUID(uid, []string{brewPath, "update"}, env) - if err != nil { - return out, err + up.Config = DriverConfiguration{ + Title: "Brew", + Description: "CLI Apps", + Enabled: true, + MultiUser: false, + DryRun: dryrun, + } + + if up.Config.DryRun { + return up, nil } - out, err = lib.RunUID(uid, []string{brewPath, "upgrade"}, env) + uid, err := up.GetBrewUID() if err != nil { - return out, err + return up, err } - return out, nil + up.BaseUser = uid + return up, nil } diff --git a/drv/distrobox.go b/drv/distrobox.go new file mode 100644 index 0000000..12ed294 --- /dev/null +++ b/drv/distrobox.go @@ -0,0 +1,83 @@ +package drv + +import ( + "fmt" + "os/exec" + + "github.com/ublue-os/uupd/lib" +) + +type DistroboxUpdater struct { + Config DriverConfiguration + Tracker *TrackerConfiguration + users []lib.User + usersEnabled bool +} + +func (up DistroboxUpdater) Steps() int { + return (1 + len(up.users)) +} + +func (up DistroboxUpdater) New(dryrun bool) (DistroboxUpdater, error) { + userdesc := "Distroboxes for User:" + up.Config = DriverConfiguration{ + Title: "Distrobox", + Description: "Rootful Distroboxes", + UserDescription: &userdesc, + Enabled: true, + MultiUser: true, + DryRun: dryrun, + } + up.usersEnabled = false + up.Tracker = nil + + return up, nil +} + +func (up *DistroboxUpdater) SetUsers(users []lib.User) { + up.users = users + up.usersEnabled = true +} + +func (up DistroboxUpdater) Check() (*[]CommandOutput, error) { + return nil, nil +} + +func (up *DistroboxUpdater) Update() (*[]CommandOutput, error) { + var finalOutput = []CommandOutput{} + + if up.Config.DryRun { + lib.ChangeTrackerMessageFancy(*up.Tracker.Writer, up.Tracker.Tracker, up.Tracker.Progress, fmt.Sprintf("Updating %s (%s)", up.Config.Description, up.Config.Title)) + up.Tracker.Tracker.IncrementSection(nil) + + var err error = nil + for _, user := range up.users { + up.Tracker.Tracker.IncrementSection(err) + lib.ChangeTrackerMessageFancy(*up.Tracker.Writer, up.Tracker.Tracker, up.Tracker.Progress, fmt.Sprintf("Updating %s %s (%s)", *up.Config.UserDescription, user.Name, up.Config.Title)) + } + return &finalOutput, nil + } + + // TODO: add env support for Flatpak and Distrobox updaters + lib.ChangeTrackerMessageFancy(*up.Tracker.Writer, up.Tracker.Tracker, up.Tracker.Progress, fmt.Sprintf("Updating %s (%s)", up.Config.Description, up.Config.Title)) + flatpakCmd := exec.Command("/usr/bin/distrobox", "upgrade", "-a") + out, err := flatpakCmd.CombinedOutput() + tmpout := CommandOutput{}.New(out, err) + if err != nil { + tmpout.SetFailureContext("System Distroboxes") + } + finalOutput = append(finalOutput, *tmpout) + + err = nil + for _, user := range up.users { + up.Tracker.Tracker.IncrementSection(err) + lib.ChangeTrackerMessageFancy(*up.Tracker.Writer, up.Tracker.Tracker, up.Tracker.Progress, fmt.Sprintf("Updating %s %s (%s)", *up.Config.UserDescription, user.Name, up.Config.Title)) + out, err := lib.RunUID(user.UID, []string{"/usr/bin/flatpak", "update", "-y"}, nil) + tmpout = CommandOutput{}.New(out, err) + if err != nil { + tmpout.SetFailureContext(fmt.Sprintf("Distroboxes for User: %s", user.Name)) + } + finalOutput = append(finalOutput, *tmpout) + } + return &finalOutput, nil +} diff --git a/drv/flatpak.go b/drv/flatpak.go new file mode 100644 index 0000000..1f87b0f --- /dev/null +++ b/drv/flatpak.go @@ -0,0 +1,82 @@ +package drv + +import ( + "fmt" + "os/exec" + + "github.com/ublue-os/uupd/lib" +) + +type FlatpakUpdater struct { + Config DriverConfiguration + Tracker *TrackerConfiguration + users []lib.User + usersEnabled bool +} + +func (up FlatpakUpdater) Steps() int { + return (1 + len(up.users)) +} + +func (up FlatpakUpdater) New(dryrun bool) (FlatpakUpdater, error) { + userdesc := "Apps for User:" + up.Config = DriverConfiguration{ + Title: "Flatpak", + Description: "System Apps", + UserDescription: &userdesc, + Enabled: true, + MultiUser: true, + DryRun: dryrun, + } + up.usersEnabled = false + up.Tracker = nil + + return up, nil +} + +func (up *FlatpakUpdater) SetUsers(users []lib.User) { + up.users = users + up.usersEnabled = true +} + +func (up FlatpakUpdater) Check() (*[]CommandOutput, error) { + return nil, nil +} + +func (up FlatpakUpdater) Update() (*[]CommandOutput, error) { + var finalOutput = []CommandOutput{} + + if up.Config.DryRun { + lib.ChangeTrackerMessageFancy(*up.Tracker.Writer, up.Tracker.Tracker, up.Tracker.Progress, fmt.Sprintf("Updating %s (%s)", up.Config.Description, up.Config.Title)) + up.Tracker.Tracker.IncrementSection(nil) + + var err error = nil + for _, user := range up.users { + up.Tracker.Tracker.IncrementSection(err) + lib.ChangeTrackerMessageFancy(*up.Tracker.Writer, up.Tracker.Tracker, up.Tracker.Progress, fmt.Sprintf("Updating %s %s (%s)", *up.Config.UserDescription, user.Name, up.Config.Title)) + } + return &finalOutput, nil + } + + lib.ChangeTrackerMessageFancy(*up.Tracker.Writer, up.Tracker.Tracker, up.Tracker.Progress, fmt.Sprintf("Updating %s (%s)", up.Config.Description, up.Config.Title)) + flatpakCmd := exec.Command("/usr/bin/flatpak", "update", "-y") + out, err := flatpakCmd.CombinedOutput() + tmpout := CommandOutput{}.New(out, err) + if err != nil { + tmpout.SetFailureContext("Flatpak System Apps") + } + finalOutput = append(finalOutput, *tmpout) + + err = nil + for _, user := range up.users { + up.Tracker.Tracker.IncrementSection(err) + lib.ChangeTrackerMessageFancy(*up.Tracker.Writer, up.Tracker.Tracker, up.Tracker.Progress, fmt.Sprintf("Updating %s %s (%s)", *up.Config.UserDescription, user.Name, up.Config.Title)) + out, err := lib.RunUID(user.UID, []string{"/usr/bin/flatpak", "update", "-y"}, nil) + tmpout = CommandOutput{}.New(out, err) + if err != nil { + tmpout.SetFailureContext(fmt.Sprintf("Flatpak User: %s", user.Name)) + } + finalOutput = append(finalOutput, *tmpout) + } + return &finalOutput, nil +} diff --git a/drv/generic.go b/drv/generic.go new file mode 100644 index 0000000..a24d8d5 --- /dev/null +++ b/drv/generic.go @@ -0,0 +1,54 @@ +package drv + +import ( + "github.com/jedib0t/go-pretty/v6/progress" + "github.com/ublue-os/uupd/lib" +) + +type CommandOutput struct { + Stdout string + Failure bool + Stderr error + Context *string +} + +func (output CommandOutput) New(out []byte, err error) *CommandOutput { + return &CommandOutput{ + Context: nil, + Failure: err != nil, + Stderr: nil, + Stdout: string(out), + } +} + +func (out *CommandOutput) SetFailureContext(context string) { + out.Failure = true + out.Context = &context +} + +type DriverConfiguration struct { + Title string + Description string + Enabled bool + MultiUser bool + DryRun bool + UserDescription *string +} + +type TrackerConfiguration struct { + Tracker *lib.IncrementTracker + Writer *progress.Writer + Progress bool +} + +type UpdateDriver interface { + Steps() int + Check() (*[]CommandOutput, error) + Update() (*[]CommandOutput, error) + New(dryrun bool) (*UpdateDriver, error) +} + +type MultiUserUpdateDriver interface { + *UpdateDriver + SetUsers(users []lib.User) +} diff --git a/drv/system.go b/drv/system.go new file mode 100644 index 0000000..e48f3ad --- /dev/null +++ b/drv/system.go @@ -0,0 +1,71 @@ +package drv + +type SystemUpdater struct { + Config DriverConfiguration + SystemDriver SystemUpdateDriver + Outdated bool + UpdateAvailable bool +} + +func (up SystemUpdater) Steps() int { + var steps = 0 + + if up.UpdateAvailable && up.Config.Enabled { + steps += 1 + } + + return steps +} + +func (up SystemUpdater) New(dryrun bool) (SystemUpdater, error) { + up.Config = DriverConfiguration{ + Title: "System", + Description: "System Update", + Enabled: true, + DryRun: dryrun, + } + + if dryrun { + up.Outdated = false + return up, nil + } + + systemDriver, err := GetSystemUpdateDriver() + if err != nil { + return up, err + } + up.SystemDriver = systemDriver + + outdated, err := up.SystemDriver.ImageOutdated() + if err != nil { + return up, err + } + + up.Outdated = outdated + return up, nil +} + +func (up *SystemUpdater) Check() (bool, error) { + if up.Config.DryRun || !up.Config.Enabled { + return true, nil + } + updateAvailable, err := up.SystemDriver.UpdateAvailable() + return updateAvailable, err +} + +func (up SystemUpdater) Update() (*[]CommandOutput, error) { + var final_output = []CommandOutput{} + + if up.Config.DryRun { + return &final_output, nil + } + + out, err := up.SystemDriver.Update() + tmpout := CommandOutput{}.New(out, err) + if err != nil { + tmpout.SetFailureContext("System update") + } + final_output = append(final_output, *tmpout) + + return &final_output, nil +} diff --git a/go.mod b/go.mod index 3b5b8d6..516e317 100644 --- a/go.mod +++ b/go.mod @@ -23,4 +23,5 @@ require ( github.com/tklauser/numcpus v0.6.1 // indirect github.com/yusufpapurcu/wmi v1.2.4 // indirect golang.org/x/sys v0.27.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/lib/percentmanager.go b/lib/percentmanager.go index 2854e96..bd14135 100644 --- a/lib/percentmanager.go +++ b/lib/percentmanager.go @@ -63,25 +63,18 @@ func ChangeTrackerMessageFancy(writer progress.Writer, tracker *IncrementTracker tracker.Tracker.UpdateMessage(message) } -func (it *IncrementTracker) IncrementSection() { +func (it *IncrementTracker) IncrementSection(err error) { var increment_step float64 if it.incrementer.doneIncrements == 0 { increment_step = 1 } else { increment_step = float64(it.Tracker.Total / int64(it.incrementer.MaxIncrements)) } - it.Tracker.Increment(int64(increment_step)) - it.incrementer.doneIncrements++ -} - -func (it *IncrementTracker) IncrementSectionError() { - var increment_step float64 - if it.incrementer.doneIncrements == 0 { - increment_step = 1 + if err == nil { + it.Tracker.Increment(int64(increment_step)) } else { - increment_step = float64(it.Tracker.Total / int64(it.incrementer.MaxIncrements)) + it.Tracker.IncrementWithError(int64(increment_step)) } - it.Tracker.IncrementWithError(int64(increment_step)) it.incrementer.doneIncrements++ }