[lxc-devel] [go-lxc/v2] bindings: adapt to new liblxc version output

brauner on Github lxc-bot at linuxcontainers.org
Thu Oct 12 13:04:01 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 668 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20171012/578080c9/attachment.bin>
-------------- next part --------------
From cbff440cf19ed6a5cc9c512d3b48c789cb9a9320 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Thu, 12 Oct 2017 15:00:10 +0200
Subject: [PATCH] bindings: adapt to new liblxc version output

liblxc will now append "-devel" (e.g. 2.1.0-devel") when LXC_DEVEL is true.
From a semantic versioning perspective liblxc is doing a saner thing than go-lxc
with appending "-devel" instead of " (devel)" but we shouldn't break existing
user. They might already rely on " (devel)" so let's keep it.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 lxc-binding.go | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lxc-binding.go b/lxc-binding.go
index dbb9689..29aaf80 100644
--- a/lxc-binding.go
+++ b/lxc-binding.go
@@ -64,9 +64,14 @@ func Release(c *Container) bool {
 // Version returns the LXC version.
 func Version() string {
 	version := C.GoString(C.lxc_get_version())
-	if C.LXC_DEVEL == 1 {
+
+	// New liblxc versions append "-devel" when LXC_DEVEL is set.
+	if strings.HasSuffix(version, "-devel") {
+		return fmt.Sprintf("%s (devel)", version[:(len(version) - len("-devel"))])
+	} else if C.LXC_DEVEL == 1 {
 		version = fmt.Sprintf("%s (devel)", version)
 	}
+
 	return version
 }
 


More information about the lxc-devel mailing list