The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/distrobuilder/pull/216
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === Signed-off-by: Thomas Hipp <thomas.h...@canonical.com>
From 0a5807e1e1b8f2cb7c7eb883e4a9682340d05913 Mon Sep 17 00:00:00 2001 From: Thomas Hipp <thomas.h...@canonical.com> Date: Wed, 14 Aug 2019 19:27:59 +0200 Subject: [PATCH] *: Various cleanups Signed-off-by: Thomas Hipp <thomas.h...@canonical.com> --- distrobuilder/main_lxc.go | 5 ----- generators/generators_test.go | 2 +- image/lxd.go | 4 ++-- shared/chroot.go | 5 +++-- shared/util_test.go | 1 + sources/fedora-http.go | 4 +--- sources/ubuntu-http.go | 9 ++++++--- 7 files changed, 14 insertions(+), 16 deletions(-) diff --git a/distrobuilder/main_lxc.go b/distrobuilder/main_lxc.go index 99cb730..f95c369 100644 --- a/distrobuilder/main_lxc.go +++ b/distrobuilder/main_lxc.go @@ -17,11 +17,6 @@ type cmdLXC struct { global *cmdGlobal } -type cmdBuildLXC struct { - cmd *cobra.Command - global *cmdGlobal -} - func (c *cmdLXC) commandBuild() *cobra.Command { c.cmdBuild = &cobra.Command{ Use: "build-lxc <filename|-> [target dir]", diff --git a/generators/generators_test.go b/generators/generators_test.go index 2721b27..c312fb9 100644 --- a/generators/generators_test.go +++ b/generators/generators_test.go @@ -50,7 +50,7 @@ func TestRestoreFiles(t *testing.T) { err = os.Chmod(cacheDir, 0600) require.NoError(t, err) - err = StoreFile(cacheDir, cacheDir, filepath.Join("/testdir1", "testfile1")) + err = StoreFile(cacheDir, rootfsDir, filepath.Join("/testdir1", "testfile1")) require.Error(t, err) // Restore permissions diff --git a/image/lxd.go b/image/lxd.go index 6d43b9c..52400a5 100644 --- a/image/lxd.go +++ b/image/lxd.go @@ -123,8 +123,8 @@ func (l *LXDImage) createMetadata() error { l.Metadata.Properties["description"], err = shared.RenderTemplate( l.definition.Image.Description, l.definition) - if err != err { - return nil + if err != nil { + return err } l.Metadata.Properties["name"], err = shared.RenderTemplate( diff --git a/shared/chroot.go b/shared/chroot.go index 22f1d7f..3f112b9 100644 --- a/shared/chroot.go +++ b/shared/chroot.go @@ -132,9 +132,10 @@ func killChrootProcesses(rootfs string) error { } // Get all processes and kill them + re := regexp.MustCompile(`\d+`) + for _, dir := range dirs { - match, _ := regexp.MatchString(`\d+`, dir) - if match { + if re.MatchString(dir) { link, _ := os.Readlink(filepath.Join(rootfs, "proc", dir, "root")) if link == rootfs { pid, _ := strconv.Atoi(dir) diff --git a/shared/util_test.go b/shared/util_test.go index 8f27f5c..a964728 100644 --- a/shared/util_test.go +++ b/shared/util_test.go @@ -211,4 +211,5 @@ func TestSetEnvVariables(t *testing.T) { val, set = os.LookupEnv("BAR") require.False(t, set, "Expected 'BAR' to be unset") + require.Empty(t, val) } diff --git a/sources/fedora-http.go b/sources/fedora-http.go index e9ed6a2..b6e3c82 100644 --- a/sources/fedora-http.go +++ b/sources/fedora-http.go @@ -17,9 +17,7 @@ import ( ) // FedoraHTTP represents the Fedora HTTP downloader. -type FedoraHTTP struct { - fname string -} +type FedoraHTTP struct{} // NewFedoraHTTP creates a new FedoraHTTP instance. func NewFedoraHTTP() *FedoraHTTP { diff --git a/sources/ubuntu-http.go b/sources/ubuntu-http.go index f300541..501a567 100644 --- a/sources/ubuntu-http.go +++ b/sources/ubuntu-http.go @@ -79,8 +79,6 @@ func (s *UbuntuHTTP) runDefaultVariant(definition shared.Definition, rootfsDir s } func (s *UbuntuHTTP) runCoreVariant(definition shared.Definition, rootfsDir string) error { - f := filepath.Join(s.fpath, s.fname) - if !lxd.PathExists(filepath.Join(s.fpath, strings.TrimSuffix(s.fname, ".xz"))) { err := shared.RunCommand("unxz", "-k", filepath.Join(s.fpath, s.fname)) if err != nil { @@ -89,7 +87,7 @@ func (s *UbuntuHTTP) runCoreVariant(definition shared.Definition, rootfsDir stri } s.fname = strings.TrimSuffix(s.fname, ".xz") - f = filepath.Join(s.fpath, s.fname) + f := filepath.Join(s.fpath, s.fname) output, err := lxd.RunCommand("fdisk", "-l", "-o", "Start", f) if err != nil { @@ -390,7 +388,12 @@ func getLatestRelease(baseURL, release, arch string) string { return "" } defer resp.Body.Close() + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + fmt.Fprintln(os.Stderr, err) + return "" + } regex := regexp.MustCompile(fmt.Sprintf("ubuntu-base-\\d{2}\\.\\d{2}(\\.\\d+)?-base-%s.tar.gz", arch)) releases := regex.FindAllString(string(body), -1)
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel