Skip to content

Commit

Permalink
i/p/requestprompts: ensure /run/snapd exists before opening max promp…
Browse files Browse the repository at this point in the history
…t id file

Signed-off-by: Oliver Calder <[email protected]>
  • Loading branch information
olivercalder authored and ernestl committed Aug 24, 2024
1 parent 4712fa8 commit 83ca902
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions interfaces/prompting/requestprompts/requestprompts.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"
"sync"
"time"
Expand Down Expand Up @@ -241,6 +242,9 @@ const (
// for a substantial amount of time (such as to lock and modify snapd state).
func New(notifyPrompt func(userID uint32, promptID prompting.IDType, data map[string]string) error) (*PromptDB, error) {
maxIDFilepath := filepath.Join(dirs.SnapRunDir, "request-prompt-max-id")
if err := os.MkdirAll(dirs.SnapRunDir, 0o755); err != nil {
return nil, err
}
maxIDMmap, err := maxidmmap.OpenMaxIDMmap(maxIDFilepath)
if err != nil {
return nil, err
Expand Down
3 changes: 2 additions & 1 deletion interfaces/prompting/requestprompts/requestprompts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ func (s *requestpromptsSuite) SetUpTest(c *C) {
s.tmpdir = c.MkDir()
dirs.SetRootDir(s.tmpdir)
s.maxIDPath = filepath.Join(dirs.SnapRunDir, "request-prompt-max-id")
c.Assert(os.MkdirAll(dirs.SnapRunDir, 0700), IsNil)
}

func (s *requestpromptsSuite) TestNew(c *C) {
Expand Down Expand Up @@ -196,6 +195,8 @@ func (s *requestpromptsSuite) TestNewNextIDUniqueIDs(c *C) {
})
defer restore()

c.Assert(os.MkdirAll(dirs.SnapRunDir, 0o755), IsNil)

var initialMaxID uint64 = 42
var initialData [8]byte
*(*uint64)(unsafe.Pointer(&initialData[0])) = initialMaxID
Expand Down

0 comments on commit 83ca902

Please sign in to comment.