Skip to content

Commit e0de7b1

Browse files
committed
Fix freebsd lint
Signed-off-by: apostasie <[email protected]>
1 parent efeb191 commit e0de7b1

File tree

6 files changed

+60
-71
lines changed

6 files changed

+60
-71
lines changed

cmd/nerdctl/container/container_cp_linux.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
package container
1818

1919
import (
20+
"errors"
2021
"fmt"
22+
"path/filepath"
23+
"strings"
2124

2225
"github.com/spf13/cobra"
2326

@@ -131,3 +134,46 @@ func processCpOptions(cmd *cobra.Command, args []string) (types.ContainerCpOptio
131134
func AddCpCommand(rootCmd *cobra.Command) {
132135
rootCmd.AddCommand(newCpCommand())
133136
}
137+
138+
var errFileSpecDoesntMatchFormat = errors.New("filespec must match the canonical format: [container:]file/path")
139+
140+
func parseCpFileSpec(arg string) (*cpFileSpec, error) {
141+
i := strings.Index(arg, ":")
142+
143+
// filespec starting with a semicolon is invalid
144+
if i == 0 {
145+
return nil, errFileSpecDoesntMatchFormat
146+
}
147+
148+
if filepath.IsAbs(arg) {
149+
// Explicit local absolute path, e.g., `C:\foo` or `/foo`.
150+
return &cpFileSpec{
151+
Container: nil,
152+
Path: arg,
153+
}, nil
154+
}
155+
156+
parts := strings.SplitN(arg, ":", 2)
157+
158+
if len(parts) == 1 || strings.HasPrefix(parts[0], ".") {
159+
// Either there's no `:` in the arg
160+
// OR it's an explicit local relative path like `./file:name.txt`.
161+
return &cpFileSpec{
162+
Path: arg,
163+
}, nil
164+
}
165+
166+
return &cpFileSpec{
167+
Container: &parts[0],
168+
Path: parts[1],
169+
}, nil
170+
}
171+
172+
type cpFileSpec struct {
173+
Container *string
174+
Path string
175+
}
176+
177+
func cpShellComplete(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
178+
return nil, cobra.ShellCompDirectiveFilterFileExt
179+
}

cmd/nerdctl/container/container_cp_unix.go

Lines changed: 0 additions & 70 deletions
This file was deleted.

pkg/containerutil/container_network_manager.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,7 @@ func writeEtcHostnameForContainer(globalOptions types.GlobalCommandOptions, host
649649

650650
// Loads all available networks and verifies that every selected network
651651
// from the networkSlice is of a type within supportedTypes.
652+
// nolint:unused
652653
func verifyNetworkTypes(env *netutil.CNIEnv, networkSlice []string, supportedTypes []string) (map[string]*netutil.NetworkConfig, error) {
653654
netMap, err := env.NetworkMap()
654655
if err != nil {

pkg/netutil/netutil_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ func TestParseIPAMRange(t *testing.T) {
133133
// Note that this test will require a CNI driver bearing the same name as
134134
// the type of the default network. (denoted by netutil.DefaultNetworkName,
135135
// which is used as both the name of the default network and its Driver)
136+
// nolint:unused
136137
func testDefaultNetworkCreation(t *testing.T) {
137138
// To prevent subnet collisions when attempting to recreate the default network
138139
// in the isolated CNI config dir we'll be using, we must first delete

pkg/ocihook/ocihook_freebsd.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@ package ocihook
1818

1919
func loadAppArmor() {
2020
//noop
21-
return
2221
}

pkg/testutil/testutil_freebsd.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package testutil
1818

19+
import "fmt"
20+
1921
const (
2022
CommonImage = "docker.io/knast/freebsd:13-STABLE"
2123

@@ -26,3 +28,13 @@ const (
2628
// https://www.rfc-editor.org/rfc/rfc793
2729
ExpectedConnectionRefusedError = "connection refused"
2830
)
31+
32+
var (
33+
AlpineImage = mirrorOf("alpine:3.13")
34+
NginxAlpineImage = mirrorOf("nginx:1.19-alpine")
35+
)
36+
37+
func mirrorOf(s string) string {
38+
// plain mirror, NOT stargz-converted images
39+
return fmt.Sprintf("ghcr.io/stargz-containers/%s-org", s)
40+
}

0 commit comments

Comments
 (0)