Skip to content
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

feat(personality): Allow state filename customization #416

Merged
merged 2 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/personality.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ var DisplayName string = "Pebble"

// DefaultDir is the Pebble directory used if $PEBBLE is not set.
var DefaultDir string = "/var/lib/pebble/default"

// StateFile is the file name of the state file in pebble dir.
var StateFile string = ".pebble.state"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess having a separate StateFile variable is better than using "."+ProgramName+".state"?

Copy link
Contributor Author

@thp-canonical thp-canonical May 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it'd allow us to be more flexible with the file name selection (e.g. could be a non-hidden file or a different filename extension, etc..).

3 changes: 2 additions & 1 deletion internals/daemon/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/gorilla/mux"
. "gopkg.in/check.v1"

"github.com/canonical/pebble/cmd"
"github.com/canonical/pebble/internals/logger"
"github.com/canonical/pebble/internals/osutil"
"github.com/canonical/pebble/internals/overlord"
Expand Down Expand Up @@ -69,7 +70,7 @@ func (s *daemonSuite) SetUpTest(c *C) {
}

s.pebbleDir = c.MkDir()
s.statePath = filepath.Join(s.pebbleDir, ".pebble.state")
s.statePath = filepath.Join(s.pebbleDir, cmd.StateFile)
systemdSdNotify = func(notif string) error {
s.notified = append(s.notified, notif)
return nil
Expand Down
3 changes: 2 additions & 1 deletion internals/overlord/overlord.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/canonical/x-go/randutil"
"gopkg.in/tomb.v2"

"github.com/canonical/pebble/cmd"
"github.com/canonical/pebble/internals/osutil"
"github.com/canonical/pebble/internals/overlord/checkstate"
"github.com/canonical/pebble/internals/overlord/cmdstate"
Expand Down Expand Up @@ -120,7 +121,7 @@ func New(opts *Options) (*Overlord, error) {
if !osutil.IsDir(o.pebbleDir) {
return nil, fmt.Errorf("directory %q does not exist", o.pebbleDir)
}
statePath := filepath.Join(o.pebbleDir, ".pebble.state")
statePath := filepath.Join(o.pebbleDir, cmd.StateFile)

backend := &overlordStateBackend{
path: statePath,
Expand Down
2 changes: 1 addition & 1 deletion internals/overlord/overlord_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func fakePruneTicker() (w *ticker, restore func()) {

func (ovs *overlordSuite) SetUpTest(c *C) {
ovs.dir = c.MkDir()
ovs.statePath = filepath.Join(ovs.dir, ".pebble.state")
ovs.statePath = filepath.Join(ovs.dir, cmd.StateFile)
}

func (ovs *overlordSuite) TearDownTest(c *C) {
Expand Down
Loading