Skip to content

Commit

Permalink
New Option to clean-up swupd state directory
Browse files Browse the repository at this point in the history
Fixes #215

We already default to placing the swupd state cache directory
in the installation target. This change implements the only
missing part of the request to allow removing the state directory.

Signed-off-by: Mark D Horn <mark.d.horn@intel.com>
  • Loading branch information
mdhorn committed Feb 15, 2019
1 parent ee86c38 commit 4667cb8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
6 changes: 6 additions & 0 deletions args/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type Args struct {
CryptPassFile string
SwupdMirror string
SwupdStateDir string
SwupdStateClean bool
SwupdFormat string
SwupdContentURL string
SwupdVersionURL string
Expand Down Expand Up @@ -151,6 +152,11 @@ func (args *Args) setCommandLineArgs() (err error) {
&args.SwupdStateDir, "swupd-state", args.SwupdMirror, "Swupd state-dir",
)

flag.BoolVar(
&args.SwupdStateClean, "swupd-clean",
false, "Clean Swupd state-dir content after install",
)

flag.StringVar(
&args.SwupdFormat, "swupd-format", args.SwupdFormat, "Swupd --format argument",
)
Expand Down
11 changes: 11 additions & 0 deletions controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,17 @@ func contentInstall(rootDir string, version string, model *model.SystemInstall,
}
prg.Success()

// Clean-up State Directory content
if options.SwupdStateClean {
msg = "Cleaning Swupd state directory"
prg = progress.NewLoop(msg)
log.Info(msg)
if err = sw.CleanUpState(); err != nil {
log.ErrorError(err)
}
prg.Success()
}

return nil, nil
}

Expand Down
14 changes: 14 additions & 0 deletions swupd/swupd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
"strings"
Expand Down Expand Up @@ -427,3 +428,16 @@ func LoadBundleList() ([]*Bundle, error) {

return root.Bundles, nil
}

// CleanUpState removes the swupd state content directory
func (s *SoftwareUpdater) CleanUpState() error {

log.Debug("Removing swupd state directory: %s", s.stateDir)

err := os.RemoveAll(s.stateDir)
if err != nil {
return errors.Wrap(err)
}

return nil
}

0 comments on commit 4667cb8

Please sign in to comment.