mirror of
https://github.com/containers/podman.git
synced 2025-05-17 23:26:08 +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
|
||||
- nolintlint
|
||||
- gocognit
|
||||
- stylecheck
|
||||
- testpackage
|
||||
- goerr113
|
||||
- exhaustivestruct
|
||||
|
@ -156,12 +156,12 @@ func imageSearch(cmd *cobra.Command, args []string) error {
|
||||
return errors.Errorf("filters are not applicable to list tags result")
|
||||
}
|
||||
if report.IsJSON(searchOptions.Format) {
|
||||
listTagsEntries := buildListTagsJson(searchReport)
|
||||
return printJson(listTagsEntries)
|
||||
listTagsEntries := buildListTagsJSON(searchReport)
|
||||
return printArbitraryJSON(listTagsEntries)
|
||||
}
|
||||
row = "{{.Name}}\t{{.Tag}}\n"
|
||||
case report.IsJSON(searchOptions.Format):
|
||||
return printJson(searchReport)
|
||||
return printArbitraryJSON(searchReport)
|
||||
case cmd.Flags().Changed("format"):
|
||||
renderHeaders = parse.HasTable(searchOptions.Format)
|
||||
row = report.NormalizeFormat(searchOptions.Format)
|
||||
@ -186,7 +186,7 @@ func imageSearch(cmd *cobra.Command, args []string) error {
|
||||
return tmpl.Execute(w, searchReport)
|
||||
}
|
||||
|
||||
func printJson(v interface{}) error {
|
||||
func printArbitraryJSON(v interface{}) error {
|
||||
prettyJSON, err := json.MarshalIndent(v, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
@ -195,7 +195,7 @@ func printJson(v interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func buildListTagsJson(searchReport []entities.ImageSearchReport) []listEntryTag {
|
||||
func buildListTagsJSON(searchReport []entities.ImageSearchReport) []listEntryTag {
|
||||
entries := []listEntryTag{}
|
||||
|
||||
ReportLoop:
|
||||
|
@ -269,9 +269,9 @@ func (s *BoltState) Refresh() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, execId := range toRemove {
|
||||
if err := ctrExecBkt.Delete([]byte(execId)); err != nil {
|
||||
return errors.Wrapf(err, "error removing exec session %s from container %s", execId, string(id))
|
||||
for _, execID := range toRemove {
|
||||
if err := ctrExecBkt.Delete([]byte(execID)); err != nil {
|
||||
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 {
|
||||
// Id is the ID of the exec session.
|
||||
// Named somewhat strangely to not conflict with ID().
|
||||
// nolint:stylecheck
|
||||
Id string `json:"id"`
|
||||
// ContainerId is the ID of the container this exec session belongs to.
|
||||
// Named somewhat strangely to not conflict with ContainerID().
|
||||
// nolint:stylecheck
|
||||
ContainerId string `json:"containerId"`
|
||||
|
||||
// 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 {
|
||||
isGidAvailable := false
|
||||
isGIDAvailable := false
|
||||
for _, m := range gidMappings {
|
||||
if gid >= m.ContainerID && gid < m.ContainerID+m.Size {
|
||||
isGidAvailable = true
|
||||
isGIDAvailable = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if isGidAvailable {
|
||||
if isGIDAvailable {
|
||||
g.AddProcessAdditionalGid(uint32(gid))
|
||||
} else {
|
||||
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
|
||||
// mount, bind mount or volume) and the resolved path on the root (absolute to
|
||||
// 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.
|
||||
pathRelativeToContainerMountPoint := 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
|
||||
// join the working dir with "/", and the add the containerPath
|
||||
// to it.
|
||||
pathRelativeToContainerMountPoint = filepath.Join(filepath.Join("/", container.WorkingDir()), containerPath)
|
||||
pathRelativeToContainerMountPoint = filepath.Join(filepath.Join("/", c.WorkingDir()), containerPath)
|
||||
}
|
||||
resolvedPathOnTheContainerMountPoint := filepath.Join(mountPoint, pathRelativeToContainerMountPoint)
|
||||
pathRelativeToContainerMountPoint = strings.TrimPrefix(pathRelativeToContainerMountPoint, mountPoint)
|
||||
@ -43,7 +43,7 @@ func (container *Container) resolvePath(mountPoint string, containerPath string)
|
||||
|
||||
searchPath := pathRelativeToContainerMountPoint
|
||||
for {
|
||||
volume, err := findVolume(container, searchPath)
|
||||
volume, err := findVolume(c, searchPath)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
@ -74,7 +74,7 @@ func (container *Container) resolvePath(mountPoint string, containerPath string)
|
||||
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)
|
||||
// We found a matching bind mount for searchPath. We
|
||||
// now need to first find the relative path of our
|
||||
|
@ -277,10 +277,10 @@ func CreateNetwork(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
body := struct {
|
||||
Id string
|
||||
ID string `json:"Id"`
|
||||
Warning []string
|
||||
}{
|
||||
Id: net.ID,
|
||||
ID: net.ID,
|
||||
}
|
||||
utils.WriteResponse(w, http.StatusCreated, body)
|
||||
}
|
||||
|
@ -270,8 +270,8 @@ func Top(ctx context.Context, nameOrID string, options *TopOptions) ([]string, e
|
||||
}
|
||||
params := url.Values{}
|
||||
if options.Changed("Descriptors") {
|
||||
ps_args := strings.Join(options.GetDescriptors(), ",")
|
||||
params.Add("ps_args", ps_args)
|
||||
psArgs := strings.Join(options.GetDescriptors(), ",")
|
||||
params.Add("ps_args", psArgs)
|
||||
}
|
||||
response, err := conn.DoRequest(nil, http.MethodGet, "/containers/%s/top", params, nil, nameOrID)
|
||||
if err != nil {
|
||||
|
@ -20,12 +20,12 @@ func handleError(data []byte) error {
|
||||
return e
|
||||
}
|
||||
|
||||
func (a APIResponse) Process(unmarshalInto interface{}) error {
|
||||
data, err := ioutil.ReadAll(a.Response.Body)
|
||||
func (h APIResponse) Process(unmarshalInto interface{}) error {
|
||||
data, err := ioutil.ReadAll(h.Response.Body)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "unable to process API response")
|
||||
}
|
||||
if a.IsSuccess() || a.IsRedirection() {
|
||||
if h.IsSuccess() || h.IsRedirection() {
|
||||
if unmarshalInto != nil {
|
||||
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
|
||||
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 {
|
||||
options = new(DisconnectOptions)
|
||||
}
|
||||
@ -117,7 +117,7 @@ func Disconnect(ctx context.Context, networkName string, ContainerNameOrId strin
|
||||
Container string
|
||||
Force bool
|
||||
}{
|
||||
Container: ContainerNameOrId,
|
||||
Container: ContainerNameOrID,
|
||||
}
|
||||
if force := options.GetForce(); options.Changed("Force") {
|
||||
disconnect.Force = force
|
||||
@ -136,7 +136,7 @@ func Disconnect(ctx context.Context, networkName string, ContainerNameOrId strin
|
||||
}
|
||||
|
||||
// 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 {
|
||||
options = new(ConnectOptions)
|
||||
}
|
||||
@ -151,7 +151,7 @@ func Connect(ctx context.Context, networkName string, ContainerNameOrId string,
|
||||
Container string
|
||||
Aliases []string
|
||||
}{
|
||||
Container: ContainerNameOrId,
|
||||
Container: ContainerNameOrID,
|
||||
}
|
||||
if aliases := options.GetAliases(); options.Changed("Aliases") {
|
||||
connect.Aliases = aliases
|
||||
|
@ -91,7 +91,7 @@ type ContainerEngine interface {
|
||||
Unshare(ctx context.Context, args []string) error
|
||||
Version(ctx context.Context) (*SystemVersionReport, 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)
|
||||
VolumeList(ctx context.Context, opts VolumeListOptions) ([]*VolumeListReport, 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.
|
||||
type NetworkReloadReport struct {
|
||||
// nolint:stylecheck
|
||||
Id string
|
||||
Err error
|
||||
}
|
||||
|
@ -61,9 +61,9 @@ var (
|
||||
gidMapOnce sync.Once
|
||||
)
|
||||
|
||||
// GetAvailableUidMap returns the UID mappings in the
|
||||
// GetAvailableUIDMap returns the UID mappings in the
|
||||
// current user namespace.
|
||||
func GetAvailableUidMap() ([]user.IDMap, error) {
|
||||
func GetAvailableUIDMap() ([]user.IDMap, error) {
|
||||
uidMapOnce.Do(func() {
|
||||
var err error
|
||||
uidMap, err = user.ParseIDMapFile("/proc/self/uid_map")
|
||||
@ -75,9 +75,9 @@ func GetAvailableUidMap() ([]user.IDMap, error) {
|
||||
return uidMap, uidMapError
|
||||
}
|
||||
|
||||
// GetAvailableGidMap returns the GID mappings in the
|
||||
// GetAvailableGIDMap returns the GID mappings in the
|
||||
// current user namespace.
|
||||
func GetAvailableGidMap() ([]user.IDMap, error) {
|
||||
func GetAvailableGIDMap() ([]user.IDMap, error) {
|
||||
gidMapOnce.Do(func() {
|
||||
var err error
|
||||
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
|
||||
// current user namespace.
|
||||
func GetAvailableIDMaps() ([]user.IDMap, []user.IDMap, error) {
|
||||
u, err := GetAvailableUidMap()
|
||||
u, err := GetAvailableUIDMap()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
g, err := GetAvailableGidMap()
|
||||
g, err := GetAvailableGIDMap()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@ -114,7 +114,7 @@ func countAvailableIDs(mappings []user.IDMap) int64 {
|
||||
// GetAvailableUids returns how many UIDs are available in the
|
||||
// current user namespace.
|
||||
func GetAvailableUids() (int64, error) {
|
||||
uids, err := GetAvailableUidMap()
|
||||
uids, err := GetAvailableUIDMap()
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
@ -125,7 +125,7 @@ func GetAvailableUids() (int64, error) {
|
||||
// GetAvailableGids returns how many GIDs are available in the
|
||||
// current user namespace.
|
||||
func GetAvailableGids() (int64, error) {
|
||||
gids, err := GetAvailableGidMap()
|
||||
gids, err := GetAvailableGIDMap()
|
||||
if err != nil {
|
||||
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 {
|
||||
return time.Unix(unix_timestamp, 0), nil
|
||||
return time.Unix(unixTimestamp, 0), nil
|
||||
}
|
||||
|
||||
// input might be a duration
|
||||
|
Reference in New Issue
Block a user