Skip to content

Commit

Permalink
global: Update to current incus/shared
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Graber <[email protected]>
  • Loading branch information
stgraber committed Oct 15, 2023
1 parent 29e94ac commit 4215612
Show file tree
Hide file tree
Showing 30 changed files with 139 additions and 144 deletions.
2 changes: 1 addition & 1 deletion distrobuilder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import (
"strings"
"time"

incus "github.com/lxc/incus/shared"
incus "github.com/lxc/incus/shared/util"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
Expand Down
6 changes: 3 additions & 3 deletions distrobuilder/main_incus.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"path/filepath"

client "github.com/lxc/incus/client"
incus "github.com/lxc/incus/shared"
"github.com/lxc/incus/shared/api"
incus "github.com/lxc/incus/shared/util"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"golang.org/x/sys/unix"
Expand Down Expand Up @@ -45,7 +45,7 @@ func (c *cmdIncus) commandBuild() *cobra.Command {
`, typeDescription, compressionDescription),
Args: cobra.RangeArgs(1, 2),
PreRunE: func(cmd *cobra.Command, args []string) error {
if !incus.StringInSlice(c.flagType, []string{"split", "unified"}) {
if !incus.ValueInSlice(c.flagType, []string{"split", "unified"}) {
return errors.New("--type needs to be one of ['split', 'unified']")
}

Expand Down Expand Up @@ -113,7 +113,7 @@ func (c *cmdIncus) commandPack() *cobra.Command {
`, typeDescription, compressionDescription),
Args: cobra.RangeArgs(2, 3),
PreRunE: func(cmd *cobra.Command, args []string) error {
if !incus.StringInSlice(c.flagType, []string{"split", "unified"}) {
if !incus.ValueInSlice(c.flagType, []string{"split", "unified"}) {
return errors.New("--type needs to be one of ['split', 'unified']")
}

Expand Down
8 changes: 4 additions & 4 deletions distrobuilder/main_repack-windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"strings"

"github.com/flosch/pongo2"
incus "github.com/lxc/incus/shared"
incus "github.com/lxc/incus/shared/util"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"golang.org/x/sys/unix"
Expand Down Expand Up @@ -110,7 +110,7 @@ func (c *cmdRepackWindows) preRun(cmd *cobra.Command, args []string) error {
} else {
supportedVersions := []string{"w11", "w10", "2k19", "2k12", "2k16", "2k22"}

if !incus.StringInSlice(c.flagWindowsVersion, supportedVersions) {
if !incus.ValueInSlice(c.flagWindowsVersion, supportedVersions) {
return fmt.Errorf("Version must be one of %v", supportedVersions)
}
}
Expand All @@ -126,7 +126,7 @@ func (c *cmdRepackWindows) preRun(cmd *cobra.Command, args []string) error {
} else {
supportedArchitectures := []string{"amd64", "ARM64"}

if !incus.StringInSlice(c.flagWindowsArchitecture, supportedArchitectures) {
if !incus.ValueInSlice(c.flagWindowsArchitecture, supportedArchitectures) {
return fmt.Errorf("Architecture must be one of %v", supportedArchitectures)
}
}
Expand Down Expand Up @@ -554,7 +554,7 @@ func (c *cmdRepackWindows) injectDrivers(dirs map[string]string) error {
targetPath := filepath.Join(targetBasePath, filepath.Base(path))

// Copy driver files
if incus.StringInSlice(ext, []string{".cat", ".dll", ".inf", ".sys"}) {
if incus.ValueInSlice(ext, []string{".cat", ".dll", ".inf", ".sys"}) {
logger.WithFields(logrus.Fields{"src": path, "dest": targetPath}).Debug("Copying file")

err := shared.Copy(path, targetPath)
Expand Down
4 changes: 2 additions & 2 deletions distrobuilder/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strconv"
"strings"

incus "github.com/lxc/incus/shared"
incus "github.com/lxc/incus/shared/util"
"golang.org/x/sys/unix"

"github.com/lxc/distrobuilder/shared"
Expand All @@ -29,7 +29,7 @@ func newVM(ctx context.Context, imageFile, rootfsDir, fs string, size uint64) (*
fs = "ext4"
}

if !incus.StringInSlice(fs, []string{"btrfs", "ext4"}) {
if !incus.ValueInSlice(fs, []string{"btrfs", "ext4"}) {
return nil, fmt.Errorf("Unsupported fs: %s", fs)
}

Expand Down
4 changes: 2 additions & 2 deletions generators/cloud-init.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"path/filepath"
"strings"

incus "github.com/lxc/incus/shared"
"github.com/lxc/incus/shared/api"
incus "github.com/lxc/incus/shared/util"

"github.com/lxc/distrobuilder/image"
"github.com/lxc/distrobuilder/shared"
Expand All @@ -29,7 +29,7 @@ func (g *cloudInit) RunLXC(img *image.LXCImage, target shared.DefinitionTargetLX
return nil
}

if incus.StringInSlice(info.Name(), []string{"cloud-init-local", "cloud-config", "cloud-init", "cloud-final"}) {
if incus.ValueInSlice(info.Name(), []string{"cloud-init-local", "cloud-config", "cloud-init", "cloud-final"}) {
err := os.Remove(path)
if err != nil {
return fmt.Errorf("Failed to remove file %q: %w", path, err)
Expand Down
2 changes: 1 addition & 1 deletion generators/cloud-init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"path/filepath"
"testing"

incus "github.com/lxc/incus/shared"
incus "github.com/lxc/incus/shared/util"
"github.com/stretchr/testify/require"

"github.com/lxc/distrobuilder/image"
Expand Down
23 changes: 17 additions & 6 deletions generators/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package generators

import (
"fmt"
"io"
"os"
"path/filepath"
"strings"

incus "github.com/lxc/incus/shared"

"github.com/lxc/distrobuilder/image"
"github.com/lxc/distrobuilder/shared"
)
Expand Down Expand Up @@ -173,18 +172,30 @@ func (g *copy) copyFile(src, dest string, defFile shared.DefinitionFile) error {
return fmt.Errorf("Failed to create directory %q: %w", dir, err)
}

err = incus.FileCopy(src, dest)
in, err := os.Open(src)
if err != nil {
return fmt.Errorf("Failed to copy file %q to %q: %w", src, dest, err)
return fmt.Errorf("Failed to open file %q: %w", src, err)
}

out, err := os.Open(dest)
out, err := os.Create(dest)
if err != nil {
return fmt.Errorf("Failed to open file %q: %w", dest, err)
if os.IsExist(err) {
out, err = os.OpenFile(dest, os.O_WRONLY, 0644)
if err != nil {
return fmt.Errorf("Failed to open file %q: %w", dest, err)
}
} else {
return fmt.Errorf("Failed to open file %q: %w", dest, err)
}
}

defer out.Close()

_, err = io.Copy(out, in)
if err != nil {
return fmt.Errorf("Failed to copy file %q: %w", dest, err)
}

err = updateFileAccess(out, defFile)
if err != nil {
return fmt.Errorf("Failed to update file access of %q: %w", dest, err)
Expand Down
2 changes: 1 addition & 1 deletion generators/hostname.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"os"
"path/filepath"

incus "github.com/lxc/incus/shared"
"github.com/lxc/incus/shared/api"
incus "github.com/lxc/incus/shared/util"

"github.com/lxc/distrobuilder/image"
"github.com/lxc/distrobuilder/shared"
Expand Down
2 changes: 1 addition & 1 deletion generators/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"path/filepath"
"strings"

incus "github.com/lxc/incus/shared"
"github.com/lxc/incus/shared/api"
incus "github.com/lxc/incus/shared/util"

"github.com/lxc/distrobuilder/image"
"github.com/lxc/distrobuilder/shared"
Expand Down
2 changes: 1 addition & 1 deletion generators/incus-agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"path/filepath"
"strings"

incus "github.com/lxc/incus/shared"
incus "github.com/lxc/incus/shared/util"

"github.com/lxc/distrobuilder/image"
"github.com/lxc/distrobuilder/shared"
Expand Down
44 changes: 21 additions & 23 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ exclude (

require (
github.com/flosch/pongo2 v0.0.0-20200913210552-0d938eb266f3
github.com/lxc/incus v0.0.0-20230914061032-a5e904192307
github.com/lxc/incus v0.0.0-20231013213300-12aef4d0bd3d
github.com/mudler/docker-companion v0.4.6-0.20211015133729-bd4704fad372
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.7.0
github.com/stretchr/testify v1.8.4
golang.org/x/sys v0.12.0
golang.org/x/sys v0.13.0
golang.org/x/text v0.13.0
gopkg.in/antchfx/htmlquery.v1 v1.2.2
gopkg.in/flosch/pongo2.v3 v3.0.0-20141028000813-5e81b817a0c4
Expand All @@ -25,21 +25,23 @@ require (
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Microsoft/hcsshim v0.11.0 // indirect
github.com/Microsoft/hcsshim v0.11.1 // indirect
github.com/antchfx/xpath v1.2.4 // indirect
github.com/apex/log v1.9.0 // indirect
github.com/containerd/cgroups v1.1.0 // indirect
github.com/containerd/containerd v1.7.6 // indirect
github.com/containerd/containerd v1.7.7 // indirect
github.com/containerd/continuity v0.4.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/docker/distribution v2.8.3+incompatible // indirect
github.com/docker/docker v24.0.6+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 // indirect
github.com/fsouza/go-dockerclient v1.9.8 // indirect
github.com/fsouza/go-dockerclient v1.10.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
Expand All @@ -49,8 +51,7 @@ require (
github.com/gorilla/websocket v1.5.0 // indirect
github.com/heroku/docker-registry-client v0.0.0-20211012143308-9463674c8930 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/klauspost/compress v1.17.1 // indirect
github.com/klauspost/pgzip v1.2.6 // indirect
github.com/kr/fs v0.1.0 // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
Expand All @@ -59,16 +60,13 @@ require (
github.com/morikuni/aec v1.0.0 // indirect
github.com/muhlemmer/gu v0.3.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc4 // indirect
github.com/opencontainers/image-spec v1.1.0-rc5 // indirect
github.com/opencontainers/runc v1.1.9 // indirect
github.com/opencontainers/runtime-spec v1.1.0 // indirect
github.com/opencontainers/umoci v0.4.8-0.20211009121349-9c76304c034d // indirect
github.com/pborman/uuid v1.2.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/sftp v1.13.6 // indirect
github.com/pkg/xattr v0.4.9 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/rootless-containers/proto/go-proto v0.0.0-20230421021042-4cd87ebadd67 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
Expand All @@ -77,16 +75,16 @@ require (
github.com/vbatts/go-mtree v0.5.3 // indirect
github.com/zitadel/oidc/v2 v2.11.0 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/oauth2 v0.12.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/term v0.12.0 // indirect
golang.org/x/tools v0.13.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/mod v0.13.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.13.0 // indirect
golang.org/x/sync v0.4.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/tools v0.14.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230913181813-007df8e322eb // indirect
google.golang.org/grpc v1.58.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231012201019-e917dd12ba7a // indirect
google.golang.org/grpc v1.58.3 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading

0 comments on commit 4215612

Please sign in to comment.