[lxc-devel] [distrobuilder/master] managers/pacman: Clean up properly

monstermunchkin on Github lxc-bot at linuxcontainers.org
Thu Feb 20 10:14:00 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 614 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200220/f2013557/attachment.bin>
-------------- next part --------------
From d3ed6b4db72c7fb78e36d7fe8fc00f896870b018 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Thu, 20 Feb 2020 11:13:09 +0100
Subject: [PATCH] managers/pacman: Clean up properly

Instead of completely removing /var/cache/pacman/pkg, we should only
remove its content.
Due to packages now being processed twice when running pack-lxc or
pack-lxd, the old behaviour caused pacman to fail when trying to install
new packages.

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 managers/pacman.go | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/managers/pacman.go b/managers/pacman.go
index d4e947b9..59147646 100644
--- a/managers/pacman.go
+++ b/managers/pacman.go
@@ -1,6 +1,7 @@
 package managers
 
 import (
+	"io/ioutil"
 	"os"
 	"path/filepath"
 	"runtime"
@@ -55,7 +56,28 @@ func NewPacman() *Manager {
 		},
 		hooks: ManagerHooks{
 			clean: func() error {
-				return os.RemoveAll("/var/cache/pacman/pkg")
+				path := "/var/cache/pacman/pkg"
+
+				// List all entries.
+				entries, err := ioutil.ReadDir(path)
+				if err != nil {
+					if os.IsNotExist(err) {
+						return nil
+					}
+
+					return errors.Wrapf(err, "Failed to list directory '%s'", path)
+				}
+
+				// Individually wipe all entries.
+				for _, entry := range entries {
+					entryPath := filepath.Join(path, entry.Name())
+					err := os.RemoveAll(entryPath)
+					if err != nil && !os.IsNotExist(err) {
+						return errors.Wrapf(err, "Failed to remove '%s'", entryPath)
+					}
+				}
+
+				return nil
 			},
 		},
 	}


More information about the lxc-devel mailing list