Skip to content

Commit 5301b8c

Browse files
Luap99mheon
authored andcommitted
libpod: return full path in sqliteStatePath()
It makes more sense for the callers. Signed-off-by: Paul Holzinger <pholzing@redhat.com> <MH: Fix cherry-pick conflicts> Signed-off-by: Matthew Heon <matthew.heon@pm.me>
1 parent b4068b4 commit 5301b8c

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

libpod/sqlite_state.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const (
4646
sqliteOptionCaseSensitiveLike = "&_cslike=TRUE"
4747

4848
// Assembled sqlite options used when opening the database.
49-
sqliteOptions = sqliteDbFilename + "?" +
49+
sqliteOptions = "?" +
5050
sqliteOptionLocation +
5151
sqliteOptionSynchronous +
5252
sqliteOptionForeignKeys +
@@ -59,12 +59,12 @@ func NewSqliteState(runtime *Runtime) (_ State, defErr error) {
5959
logrus.Info("Using sqlite as database backend")
6060
state := new(SQLiteState)
6161

62-
basePath, _ := sqliteStatePath(runtime)
62+
dbPath := sqliteStatePath(runtime)
6363

6464
// c/storage is set up *after* the DB - so even though we use the c/s
6565
// root (or, for transient, runroot) dir, we need to make the dir
6666
// ourselves.
67-
if err := os.MkdirAll(basePath, 0o700); err != nil {
67+
if err := os.MkdirAll(filepath.Dir(dbPath), 0o700); err != nil {
6868
return nil, fmt.Errorf("creating root directory: %w", err)
6969
}
7070

@@ -79,7 +79,7 @@ func NewSqliteState(runtime *Runtime) (_ State, defErr error) {
7979
}
8080
sqliteOptionBusyTimeout := "&_busy_timeout=" + busyTimeout
8181

82-
conn, err := sql.Open("sqlite3", filepath.Join(basePath, sqliteOptions+sqliteOptionBusyTimeout))
82+
conn, err := sql.Open("sqlite3", dbPath+sqliteOptions+sqliteOptionBusyTimeout)
8383
if err != nil {
8484
return nil, fmt.Errorf("initializing sqlite database: %w", err)
8585
}

libpod/sqlite_state_internal.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"errors"
88
"fmt"
99
"os"
10+
"path/filepath"
1011
"slices"
1112
"sort"
1213
"strings"
@@ -19,16 +20,15 @@ import (
1920
_ "github.com/mattn/go-sqlite3"
2021
)
2122

22-
// Returns two strings. First is base path - directory we'll create in.
23-
// Second is the filename of the database itself.
24-
func sqliteStatePath(runtime *Runtime) (string, string) {
23+
// sqliteStatePath returns the path to the sqlite file.
24+
func sqliteStatePath(runtime *Runtime) string {
2525
basePath := runtime.storageConfig.GraphRoot
2626
if runtime.storageConfig.TransientStore {
2727
basePath = runtime.storageConfig.RunRoot
2828
} else if !runtime.storageSet.StaticDirSet {
2929
basePath = runtime.config.Engine.StaticDir
3030
}
31-
return basePath, sqliteDbFilename
31+
return filepath.Join(basePath, sqliteDbFilename)
3232
}
3333

3434
func initSQLiteDB(conn *sql.DB) (defErr error) {

0 commit comments

Comments
 (0)