mirror of
https://github.com/containers/podman.git
synced 2025-07-04 01:48:28 +08:00
Enable stylecheck linter
Use the stylecheck linter and fix the reported problems. [NO TESTS NEEDED] Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
This commit is contained in:
@ -20,7 +20,6 @@ linters:
|
|||||||
# All these break for one reason or another
|
# All these break for one reason or another
|
||||||
- nolintlint
|
- nolintlint
|
||||||
- gocognit
|
- gocognit
|
||||||
- stylecheck
|
|
||||||
- testpackage
|
- testpackage
|
||||||
- goerr113
|
- goerr113
|
||||||
- exhaustivestruct
|
- exhaustivestruct
|
||||||
|
@ -156,12 +156,12 @@ func imageSearch(cmd *cobra.Command, args []string) error {
|
|||||||
return errors.Errorf("filters are not applicable to list tags result")
|
return errors.Errorf("filters are not applicable to list tags result")
|
||||||
}
|
}
|
||||||
if report.IsJSON(searchOptions.Format) {
|
if report.IsJSON(searchOptions.Format) {
|
||||||
listTagsEntries := buildListTagsJson(searchReport)
|
listTagsEntries := buildListTagsJSON(searchReport)
|
||||||
return printJson(listTagsEntries)
|
return printArbitraryJSON(listTagsEntries)
|
||||||
}
|
}
|
||||||
row = "{{.Name}}\t{{.Tag}}\n"
|
row = "{{.Name}}\t{{.Tag}}\n"
|
||||||
case report.IsJSON(searchOptions.Format):
|
case report.IsJSON(searchOptions.Format):
|
||||||
return printJson(searchReport)
|
return printArbitraryJSON(searchReport)
|
||||||
case cmd.Flags().Changed("format"):
|
case cmd.Flags().Changed("format"):
|
||||||
renderHeaders = parse.HasTable(searchOptions.Format)
|
renderHeaders = parse.HasTable(searchOptions.Format)
|
||||||
row = report.NormalizeFormat(searchOptions.Format)
|
row = report.NormalizeFormat(searchOptions.Format)
|
||||||
@ -186,7 +186,7 @@ func imageSearch(cmd *cobra.Command, args []string) error {
|
|||||||
return tmpl.Execute(w, searchReport)
|
return tmpl.Execute(w, searchReport)
|
||||||
}
|
}
|
||||||
|
|
||||||
func printJson(v interface{}) error {
|
func printArbitraryJSON(v interface{}) error {
|
||||||
prettyJSON, err := json.MarshalIndent(v, "", " ")
|
prettyJSON, err := json.MarshalIndent(v, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -195,7 +195,7 @@ func printJson(v interface{}) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildListTagsJson(searchReport []entities.ImageSearchReport) []listEntryTag {
|
func buildListTagsJSON(searchReport []entities.ImageSearchReport) []listEntryTag {
|
||||||
entries := []listEntryTag{}
|
entries := []listEntryTag{}
|
||||||
|
|
||||||
ReportLoop:
|
ReportLoop:
|
||||||
|
@ -269,9 +269,9 @@ func (s *BoltState) Refresh() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, execId := range toRemove {
|
for _, execID := range toRemove {
|
||||||
if err := ctrExecBkt.Delete([]byte(execId)); err != nil {
|
if err := ctrExecBkt.Delete([]byte(execID)); err != nil {
|
||||||
return errors.Wrapf(err, "error removing exec session %s from container %s", execId, string(id))
|
return errors.Wrapf(err, "error removing exec session %s from container %s", execID, string(id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,9 +78,11 @@ type ExecConfig struct {
|
|||||||
type ExecSession struct {
|
type ExecSession struct {
|
||||||
// Id is the ID of the exec session.
|
// Id is the ID of the exec session.
|
||||||
// Named somewhat strangely to not conflict with ID().
|
// Named somewhat strangely to not conflict with ID().
|
||||||
|
// nolint:stylecheck
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
// ContainerId is the ID of the container this exec session belongs to.
|
// ContainerId is the ID of the container this exec session belongs to.
|
||||||
// Named somewhat strangely to not conflict with ContainerID().
|
// Named somewhat strangely to not conflict with ContainerID().
|
||||||
|
// nolint:stylecheck
|
||||||
ContainerId string `json:"containerId"`
|
ContainerId string `json:"containerId"`
|
||||||
|
|
||||||
// State is the state of the exec session.
|
// State is the state of the exec session.
|
||||||
|
@ -521,14 +521,14 @@ func (c *Container) generateSpec(ctx context.Context) (*spec.Spec, error) {
|
|||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
for _, gid := range execUser.Sgids {
|
for _, gid := range execUser.Sgids {
|
||||||
isGidAvailable := false
|
isGIDAvailable := false
|
||||||
for _, m := range gidMappings {
|
for _, m := range gidMappings {
|
||||||
if gid >= m.ContainerID && gid < m.ContainerID+m.Size {
|
if gid >= m.ContainerID && gid < m.ContainerID+m.Size {
|
||||||
isGidAvailable = true
|
isGIDAvailable = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if isGidAvailable {
|
if isGIDAvailable {
|
||||||
g.AddProcessAdditionalGid(uint32(gid))
|
g.AddProcessAdditionalGid(uint32(gid))
|
||||||
} else {
|
} else {
|
||||||
logrus.Warnf("additional gid=%d is not present in the user namespace, skip setting it", gid)
|
logrus.Warnf("additional gid=%d is not present in the user namespace, skip setting it", gid)
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
// mountPoint (e.g., via a mount or volume), the resolved root (e.g., container
|
// mountPoint (e.g., via a mount or volume), the resolved root (e.g., container
|
||||||
// mount, bind mount or volume) and the resolved path on the root (absolute to
|
// mount, bind mount or volume) and the resolved path on the root (absolute to
|
||||||
// the host).
|
// the host).
|
||||||
func (container *Container) resolvePath(mountPoint string, containerPath string) (string, string, error) {
|
func (c *Container) resolvePath(mountPoint string, containerPath string) (string, string, error) {
|
||||||
// Let's first make sure we have a path relative to the mount point.
|
// Let's first make sure we have a path relative to the mount point.
|
||||||
pathRelativeToContainerMountPoint := containerPath
|
pathRelativeToContainerMountPoint := containerPath
|
||||||
if !filepath.IsAbs(containerPath) {
|
if !filepath.IsAbs(containerPath) {
|
||||||
@ -26,7 +26,7 @@ func (container *Container) resolvePath(mountPoint string, containerPath string)
|
|||||||
// container's working dir. To be extra careful, let's first
|
// container's working dir. To be extra careful, let's first
|
||||||
// join the working dir with "/", and the add the containerPath
|
// join the working dir with "/", and the add the containerPath
|
||||||
// to it.
|
// to it.
|
||||||
pathRelativeToContainerMountPoint = filepath.Join(filepath.Join("/", container.WorkingDir()), containerPath)
|
pathRelativeToContainerMountPoint = filepath.Join(filepath.Join("/", c.WorkingDir()), containerPath)
|
||||||
}
|
}
|
||||||
resolvedPathOnTheContainerMountPoint := filepath.Join(mountPoint, pathRelativeToContainerMountPoint)
|
resolvedPathOnTheContainerMountPoint := filepath.Join(mountPoint, pathRelativeToContainerMountPoint)
|
||||||
pathRelativeToContainerMountPoint = strings.TrimPrefix(pathRelativeToContainerMountPoint, mountPoint)
|
pathRelativeToContainerMountPoint = strings.TrimPrefix(pathRelativeToContainerMountPoint, mountPoint)
|
||||||
@ -43,7 +43,7 @@ func (container *Container) resolvePath(mountPoint string, containerPath string)
|
|||||||
|
|
||||||
searchPath := pathRelativeToContainerMountPoint
|
searchPath := pathRelativeToContainerMountPoint
|
||||||
for {
|
for {
|
||||||
volume, err := findVolume(container, searchPath)
|
volume, err := findVolume(c, searchPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
@ -74,7 +74,7 @@ func (container *Container) resolvePath(mountPoint string, containerPath string)
|
|||||||
return mountPoint, absolutePathOnTheVolumeMount, nil
|
return mountPoint, absolutePathOnTheVolumeMount, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if mount := findBindMount(container, searchPath); mount != nil {
|
if mount := findBindMount(c, searchPath); mount != nil {
|
||||||
logrus.Debugf("Container path %q resolved to bind mount %q:%q on path %q", containerPath, mount.Source, mount.Destination, searchPath)
|
logrus.Debugf("Container path %q resolved to bind mount %q:%q on path %q", containerPath, mount.Source, mount.Destination, searchPath)
|
||||||
// We found a matching bind mount for searchPath. We
|
// We found a matching bind mount for searchPath. We
|
||||||
// now need to first find the relative path of our
|
// now need to first find the relative path of our
|
||||||
|
@ -277,10 +277,10 @@ func CreateNetwork(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
body := struct {
|
body := struct {
|
||||||
Id string
|
ID string `json:"Id"`
|
||||||
Warning []string
|
Warning []string
|
||||||
}{
|
}{
|
||||||
Id: net.ID,
|
ID: net.ID,
|
||||||
}
|
}
|
||||||
utils.WriteResponse(w, http.StatusCreated, body)
|
utils.WriteResponse(w, http.StatusCreated, body)
|
||||||
}
|
}
|
||||||
|
@ -270,8 +270,8 @@ func Top(ctx context.Context, nameOrID string, options *TopOptions) ([]string, e
|
|||||||
}
|
}
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
if options.Changed("Descriptors") {
|
if options.Changed("Descriptors") {
|
||||||
ps_args := strings.Join(options.GetDescriptors(), ",")
|
psArgs := strings.Join(options.GetDescriptors(), ",")
|
||||||
params.Add("ps_args", ps_args)
|
params.Add("ps_args", psArgs)
|
||||||
}
|
}
|
||||||
response, err := conn.DoRequest(nil, http.MethodGet, "/containers/%s/top", params, nil, nameOrID)
|
response, err := conn.DoRequest(nil, http.MethodGet, "/containers/%s/top", params, nil, nameOrID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -20,12 +20,12 @@ func handleError(data []byte) error {
|
|||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a APIResponse) Process(unmarshalInto interface{}) error {
|
func (h APIResponse) Process(unmarshalInto interface{}) error {
|
||||||
data, err := ioutil.ReadAll(a.Response.Body)
|
data, err := ioutil.ReadAll(h.Response.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "unable to process API response")
|
return errors.Wrap(err, "unable to process API response")
|
||||||
}
|
}
|
||||||
if a.IsSuccess() || a.IsRedirection() {
|
if h.IsSuccess() || h.IsRedirection() {
|
||||||
if unmarshalInto != nil {
|
if unmarshalInto != nil {
|
||||||
return json.Unmarshal(data, unmarshalInto)
|
return json.Unmarshal(data, unmarshalInto)
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ func List(ctx context.Context, options *ListOptions) ([]*entities.NetworkListRep
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Disconnect removes a container from a given network
|
// Disconnect removes a container from a given network
|
||||||
func Disconnect(ctx context.Context, networkName string, ContainerNameOrId string, options *DisconnectOptions) error {
|
func Disconnect(ctx context.Context, networkName string, ContainerNameOrID string, options *DisconnectOptions) error {
|
||||||
if options == nil {
|
if options == nil {
|
||||||
options = new(DisconnectOptions)
|
options = new(DisconnectOptions)
|
||||||
}
|
}
|
||||||
@ -117,7 +117,7 @@ func Disconnect(ctx context.Context, networkName string, ContainerNameOrId strin
|
|||||||
Container string
|
Container string
|
||||||
Force bool
|
Force bool
|
||||||
}{
|
}{
|
||||||
Container: ContainerNameOrId,
|
Container: ContainerNameOrID,
|
||||||
}
|
}
|
||||||
if force := options.GetForce(); options.Changed("Force") {
|
if force := options.GetForce(); options.Changed("Force") {
|
||||||
disconnect.Force = force
|
disconnect.Force = force
|
||||||
@ -136,7 +136,7 @@ func Disconnect(ctx context.Context, networkName string, ContainerNameOrId strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Connect adds a container to a network
|
// Connect adds a container to a network
|
||||||
func Connect(ctx context.Context, networkName string, ContainerNameOrId string, options *ConnectOptions) error {
|
func Connect(ctx context.Context, networkName string, ContainerNameOrID string, options *ConnectOptions) error {
|
||||||
if options == nil {
|
if options == nil {
|
||||||
options = new(ConnectOptions)
|
options = new(ConnectOptions)
|
||||||
}
|
}
|
||||||
@ -151,7 +151,7 @@ func Connect(ctx context.Context, networkName string, ContainerNameOrId string,
|
|||||||
Container string
|
Container string
|
||||||
Aliases []string
|
Aliases []string
|
||||||
}{
|
}{
|
||||||
Container: ContainerNameOrId,
|
Container: ContainerNameOrID,
|
||||||
}
|
}
|
||||||
if aliases := options.GetAliases(); options.Changed("Aliases") {
|
if aliases := options.GetAliases(); options.Changed("Aliases") {
|
||||||
connect.Aliases = aliases
|
connect.Aliases = aliases
|
||||||
|
@ -91,7 +91,7 @@ type ContainerEngine interface {
|
|||||||
Unshare(ctx context.Context, args []string) error
|
Unshare(ctx context.Context, args []string) error
|
||||||
Version(ctx context.Context) (*SystemVersionReport, error)
|
Version(ctx context.Context) (*SystemVersionReport, error)
|
||||||
VolumeCreate(ctx context.Context, opts VolumeCreateOptions) (*IDOrNameResponse, error)
|
VolumeCreate(ctx context.Context, opts VolumeCreateOptions) (*IDOrNameResponse, error)
|
||||||
VolumeExists(ctx context.Context, namesOrId string) (*BoolReport, error)
|
VolumeExists(ctx context.Context, namesOrID string) (*BoolReport, error)
|
||||||
VolumeInspect(ctx context.Context, namesOrIds []string, opts InspectOptions) ([]*VolumeInspectReport, []error, error)
|
VolumeInspect(ctx context.Context, namesOrIds []string, opts InspectOptions) ([]*VolumeInspectReport, []error, error)
|
||||||
VolumeList(ctx context.Context, opts VolumeListOptions) ([]*VolumeListReport, error)
|
VolumeList(ctx context.Context, opts VolumeListOptions) ([]*VolumeListReport, error)
|
||||||
VolumePrune(ctx context.Context, options VolumePruneOptions) ([]*reports.PruneReport, error)
|
VolumePrune(ctx context.Context, options VolumePruneOptions) ([]*reports.PruneReport, error)
|
||||||
|
@ -31,6 +31,7 @@ type NetworkReloadOptions struct {
|
|||||||
|
|
||||||
// NetworkReloadReport describes the results of reloading a container network.
|
// NetworkReloadReport describes the results of reloading a container network.
|
||||||
type NetworkReloadReport struct {
|
type NetworkReloadReport struct {
|
||||||
|
// nolint:stylecheck
|
||||||
Id string
|
Id string
|
||||||
Err error
|
Err error
|
||||||
}
|
}
|
||||||
|
@ -61,9 +61,9 @@ var (
|
|||||||
gidMapOnce sync.Once
|
gidMapOnce sync.Once
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetAvailableUidMap returns the UID mappings in the
|
// GetAvailableUIDMap returns the UID mappings in the
|
||||||
// current user namespace.
|
// current user namespace.
|
||||||
func GetAvailableUidMap() ([]user.IDMap, error) {
|
func GetAvailableUIDMap() ([]user.IDMap, error) {
|
||||||
uidMapOnce.Do(func() {
|
uidMapOnce.Do(func() {
|
||||||
var err error
|
var err error
|
||||||
uidMap, err = user.ParseIDMapFile("/proc/self/uid_map")
|
uidMap, err = user.ParseIDMapFile("/proc/self/uid_map")
|
||||||
@ -75,9 +75,9 @@ func GetAvailableUidMap() ([]user.IDMap, error) {
|
|||||||
return uidMap, uidMapError
|
return uidMap, uidMapError
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAvailableGidMap returns the GID mappings in the
|
// GetAvailableGIDMap returns the GID mappings in the
|
||||||
// current user namespace.
|
// current user namespace.
|
||||||
func GetAvailableGidMap() ([]user.IDMap, error) {
|
func GetAvailableGIDMap() ([]user.IDMap, error) {
|
||||||
gidMapOnce.Do(func() {
|
gidMapOnce.Do(func() {
|
||||||
var err error
|
var err error
|
||||||
gidMap, err = user.ParseIDMapFile("/proc/self/gid_map")
|
gidMap, err = user.ParseIDMapFile("/proc/self/gid_map")
|
||||||
@ -92,11 +92,11 @@ func GetAvailableGidMap() ([]user.IDMap, error) {
|
|||||||
// GetAvailableIDMaps returns the UID and GID mappings in the
|
// GetAvailableIDMaps returns the UID and GID mappings in the
|
||||||
// current user namespace.
|
// current user namespace.
|
||||||
func GetAvailableIDMaps() ([]user.IDMap, []user.IDMap, error) {
|
func GetAvailableIDMaps() ([]user.IDMap, []user.IDMap, error) {
|
||||||
u, err := GetAvailableUidMap()
|
u, err := GetAvailableUIDMap()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
g, err := GetAvailableGidMap()
|
g, err := GetAvailableGIDMap()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
@ -114,7 +114,7 @@ func countAvailableIDs(mappings []user.IDMap) int64 {
|
|||||||
// GetAvailableUids returns how many UIDs are available in the
|
// GetAvailableUids returns how many UIDs are available in the
|
||||||
// current user namespace.
|
// current user namespace.
|
||||||
func GetAvailableUids() (int64, error) {
|
func GetAvailableUids() (int64, error) {
|
||||||
uids, err := GetAvailableUidMap()
|
uids, err := GetAvailableUIDMap()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
@ -125,7 +125,7 @@ func GetAvailableUids() (int64, error) {
|
|||||||
// GetAvailableGids returns how many GIDs are available in the
|
// GetAvailableGids returns how many GIDs are available in the
|
||||||
// current user namespace.
|
// current user namespace.
|
||||||
func GetAvailableGids() (int64, error) {
|
func GetAvailableGids() (int64, error) {
|
||||||
gids, err := GetAvailableGidMap()
|
gids, err := GetAvailableGIDMap()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
@ -530,9 +530,9 @@ func ParseInputTime(inputTime string) (time.Time, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unix_timestamp, err := strconv.ParseInt(inputTime, 10, 64)
|
unixTimestamp, err := strconv.ParseInt(inputTime, 10, 64)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return time.Unix(unix_timestamp, 0), nil
|
return time.Unix(unixTimestamp, 0), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// input might be a duration
|
// input might be a duration
|
||||||
|
Reference in New Issue
Block a user