Skip to content

Commit

Permalink
Also clean old debconf and dpkg conf
Browse files Browse the repository at this point in the history
  • Loading branch information
upils committed Oct 17, 2023
1 parent 229f664 commit 84a2e75
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
14 changes: 14 additions & 0 deletions internal/statemachine/classic_states.go
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,20 @@ func (stateMachine *StateMachine) cleanRootfs() error {

toClean = append(toClean, sshPrivKeys...)

oldDebconf, err := filepath.Glob(filepath.Join(stateMachine.tempDirs.chroot, "var", "cache", "debconf", "*-old"))
if err != nil {
return fmt.Errorf("unable to list old debconf conf: %s", err.Error())

Check warning on line 1436 in internal/statemachine/classic_states.go

View check run for this annotation

Codecov / codecov/patch

internal/statemachine/classic_states.go#L1436

Added line #L1436 was not covered by tests
}

toClean = append(toClean, oldDebconf...)

oldDpkg, err := filepath.Glob(filepath.Join(stateMachine.tempDirs.chroot, "var", "lib", "dpkg", "*-old"))
if err != nil {
return fmt.Errorf("unable to list old dpkg conf: %s", err.Error())

Check warning on line 1443 in internal/statemachine/classic_states.go

View check run for this annotation

Codecov / codecov/patch

internal/statemachine/classic_states.go#L1443

Added line #L1443 was not covered by tests
}

toClean = append(toClean, oldDpkg...)

for _, f := range toClean {
err = osRemove(f)
if err != nil && !os.IsNotExist(err) {
Expand Down
13 changes: 11 additions & 2 deletions internal/statemachine/classic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4134,8 +4134,8 @@ func TestStateMachine_defaultLocaleFailures(t *testing.T) {
})
}

func TestStateMachine_cleanRootfs(t *testing.T) {
t.Run("test_clean_rootfs", func(t *testing.T) {
func TestClassicStateMachine_cleanRootfs_real_rootfs(t *testing.T) {
t.Run("test_clean_rootfs_real_rootfs", func(t *testing.T) {
asserter := helper.Asserter{T: t}
restoreCWD := helper.SaveCWD()
t.Cleanup(restoreCWD)
Expand Down Expand Up @@ -4177,6 +4177,9 @@ func TestStateMachine_cleanRootfs(t *testing.T) {
err = stateMachine.installPackages()
asserter.AssertErrNil(err, true)

err = stateMachine.cleanRootfs()
asserter.AssertErrNil(err, true)

// Check cleaned files were removed
cleaned := []string{
filepath.Join(stateMachine.tempDirs.chroot, "etc", "machine-id"),
Expand Down Expand Up @@ -4266,6 +4269,8 @@ func TestClassicStateMachine_cleanRootfs(t *testing.T) {
filepath.Join("var", "lib", "dbus", "machine-id"),
filepath.Join("etc", "udev", "rules.d", "test-persistent-net.rules"),
filepath.Join("etc", "udev", "rules.d", "test2-persistent-net.rules"),
filepath.Join("var", "cache", "debconf", "test-old"),
filepath.Join("var", "lib", "dpkg", "testdpkg-old"),
},
wantRootfsContent: map[string]int64{
filepath.Join("etc", "udev", "rules.d", "test-persistent-net.rules"): 0,
Expand All @@ -4287,11 +4292,15 @@ func TestClassicStateMachine_cleanRootfs(t *testing.T) {
filepath.Join("etc", "machine-id"),
filepath.Join("var", "lib", "dbus", "machine-id"),
filepath.Join("etc", "udev", "rules.d", "test-persistent-net.rules"),
filepath.Join("var", "cache", "debconf", "test-old"),
filepath.Join("var", "lib", "dpkg", "testdpkg-old"),
},
wantRootfsContent: map[string]int64{
filepath.Join("etc", "machine-id"): sampleSize,
filepath.Join("var", "lib", "dbus", "machine-id"): sampleSize,
filepath.Join("etc", "udev", "rules.d", "test-persistent-net.rules"): sampleSize,
filepath.Join("var", "cache", "debconf", "test-old"): sampleSize,
filepath.Join("var", "lib", "dpkg", "testdpkg-old"): sampleSize,
},
},
{
Expand Down

0 comments on commit 84a2e75

Please sign in to comment.