[lxc-devel] [distrobuilder/master] managers: Add preRefresh hook
monstermunchkin on Github
lxc-bot at linuxcontainers.org
Thu Feb 20 15:06:53 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 310 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200220/800ec971/attachment.bin>
-------------- next part --------------
From 80452e395b66cb42c10041e99442f17b9cc1c0ca Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Thu, 20 Feb 2020 16:04:45 +0100
Subject: [PATCH 1/2] managers: Add preRefresh hook
This adds the preRefresh hook which will run before a refresh.
Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
managers/manager.go | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/managers/manager.go b/managers/manager.go
index 09945aaa..274ea724 100644
--- a/managers/manager.go
+++ b/managers/manager.go
@@ -14,7 +14,8 @@ type ManagerFlags struct {
// ManagerHooks represents custom hooks.
type ManagerHooks struct {
- clean func() error
+ clean func() error
+ preRefresh func() error
}
// ManagerCommands represents all commands.
@@ -139,6 +140,13 @@ func (m Manager) Refresh() error {
return nil
}
+ if m.hooks.preRefresh != nil {
+ err := m.hooks.preRefresh()
+ if err != nil {
+ return err
+ }
+ }
+
args := append(m.flags.global, m.flags.refresh...)
return shared.RunCommand(m.commands.refresh, args...)
From e0005e85bacaaa6397106a7e867c8beabe488baf Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Thu, 20 Feb 2020 16:05:34 +0100
Subject: [PATCH 2/2] managers/opkg: Use preRefresh hook
Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
managers/opkg.go | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/managers/opkg.go b/managers/opkg.go
index f185a1a5..25eb8e34 100644
--- a/managers/opkg.go
+++ b/managers/opkg.go
@@ -1,5 +1,7 @@
package managers
+import "os"
+
// NewOpkg creates a new Manager instance.
func NewOpkg() *Manager {
return &Manager{
@@ -28,5 +30,10 @@ func NewOpkg() *Manager {
"Not supported",
},
},
+ hooks: ManagerHooks{
+ preRefresh: func() error {
+ return os.MkdirAll("/var/lock", 0755)
+ },
+ },
}
}
More information about the lxc-devel
mailing list