Skip to content

Commit 4a0b230

Browse files
Merge pull request #24775 from mheon/fix_24738
In SQLite state, use defaults for empty-string checks
2 parents 0935710 + cb53abc commit 4a0b230

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

libpod/sqlite_state.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,30 @@ func (s *SQLiteState) ValidateDBConfig(runtime *Runtime) (defErr error) {
383383
return fmt.Errorf("retrieving DB config: %w", err)
384384
}
385385

386+
// Sometimes, for as-yet unclear reasons, the database value ends up set
387+
// to the empty string. If it does, this evaluation is always going to
388+
// fail, and libpod will be unusable.
389+
// At this point, the check is effectively meaningless - we don't
390+
// actually know the settings we should be checking against. The best
391+
// thing we can do (and what BoltDB did in this case) is to compare
392+
// against the default, on the assumption that is what was in use.
393+
// TODO: We can't remove this code without breaking existing SQLite DBs
394+
// that already have incorrect values in the database, but we should
395+
// investigate why this is happening and try and prevent the creation of
396+
// new databases with these garbage checks.
397+
if graphRoot == "" {
398+
logrus.Debugf("Database uses empty-string graph root, substituting default %q", storeOpts.GraphRoot)
399+
graphRoot = storeOpts.GraphRoot
400+
}
401+
if runRoot == "" {
402+
logrus.Debugf("Database uses empty-string run root, substituting default %q", storeOpts.RunRoot)
403+
runRoot = storeOpts.RunRoot
404+
}
405+
if graphDriver == "" {
406+
logrus.Debugf("Database uses empty-string graph driver, substituting default %q", storeOpts.GraphDriverName)
407+
graphDriver = storeOpts.GraphDriverName
408+
}
409+
386410
checkField := func(fieldName, dbVal, ourVal string, isPath bool) error {
387411
if isPath {
388412
// Tolerate symlinks when possible - most relevant for OStree systems

test/system/005-info.bats

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,4 +305,27 @@ EOF
305305
run_podman $safe_opts system reset --force
306306
}
307307

308+
@test "podman - empty string defaults for certain values" {
309+
skip_if_remote "Test uses nonstandard paths for c/storage directories"
310+
311+
# We just want this to be empty - so graph driver will be set to the empty string
312+
touch $PODMAN_TMPDIR/storage.conf
313+
314+
safe_opts=$(podman_isolation_opts ${PODMAN_TMPDIR})
315+
316+
# Force all custom directories so we don't pick up an existing database
317+
CONTAINERS_STORAGE_CONF=$PODMAN_TMPDIR/storage.conf run_podman 0+w $safe_opts info
318+
require_warning "The storage 'driver' option should be set" \
319+
"c/storage should warn on empty storage driver"
320+
321+
# Now add a valid graph driver to storage.conf
322+
cat >$PODMAN_TMPDIR/storage.conf <<EOF
323+
[storage]
324+
driver="$(podman_storage_driver)"
325+
EOF
326+
327+
# Second run of Podman should still succeed after editing the graph driver.
328+
CONTAINERS_STORAGE_CONF=$PODMAN_TMPDIR/storage.conf run_podman $safe_opts info
329+
}
330+
308331
# vim: filetype=sh

0 commit comments

Comments
 (0)