mirror of
				https://github.com/containers/podman.git
				synced 2025-10-31 10:00:01 +08:00 
			
		
		
		
	 942f789a88
			
		
	
	942f789a88
	
	
	
		
			
			The new golangci-lint version 1.60.1 has problems with typecheck when linting remote files. We have certain pakcages that should never be inlcuded in remote but the typecheck tries to compile all of them but this never works and it seems to ignore the exclude files we gave it. To fix this the proper way is to mark all packages we only use locally with !remote tags. This is a bit ugly but more correct. I also moved the DecodeChanges() code around as it is called from the client so the handles package which should only be remote doesn't really fit anyway. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
		
			
				
	
	
		
			88 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			88 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| //go:build !remote
 | |
| 
 | |
| package compat
 | |
| 
 | |
| import (
 | |
| 	"errors"
 | |
| 	"fmt"
 | |
| 	"net/http"
 | |
| 	"strings"
 | |
| 
 | |
| 	"github.com/containers/common/pkg/resize"
 | |
| 	"github.com/containers/podman/v5/libpod"
 | |
| 	"github.com/containers/podman/v5/libpod/define"
 | |
| 	"github.com/containers/podman/v5/pkg/api/handlers/utils"
 | |
| 	api "github.com/containers/podman/v5/pkg/api/types"
 | |
| 	"github.com/gorilla/mux"
 | |
| )
 | |
| 
 | |
| func ResizeTTY(w http.ResponseWriter, r *http.Request) {
 | |
| 	runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
 | |
| 	decoder := utils.GetDecoder(r)
 | |
| 
 | |
| 	// /containers/{id}/resize
 | |
| 	query := struct {
 | |
| 		Height           uint16 `schema:"h"`
 | |
| 		Width            uint16 `schema:"w"`
 | |
| 		IgnoreNotRunning bool   `schema:"running"`
 | |
| 	}{
 | |
| 		// override any golang type defaults
 | |
| 	}
 | |
| 
 | |
| 	if err := decoder.Decode(&query, r.URL.Query()); err != nil {
 | |
| 		utils.Error(w, http.StatusBadRequest, fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
 | |
| 		return
 | |
| 	}
 | |
| 
 | |
| 	sz := resize.TerminalSize{
 | |
| 		Width:  query.Width,
 | |
| 		Height: query.Height,
 | |
| 	}
 | |
| 
 | |
| 	var status int
 | |
| 	switch {
 | |
| 	case strings.Contains(r.URL.Path, "/containers/"):
 | |
| 		name := utils.GetName(r)
 | |
| 		ctnr, err := runtime.LookupContainer(name)
 | |
| 		if err != nil {
 | |
| 			utils.ContainerNotFound(w, name, err)
 | |
| 			return
 | |
| 		}
 | |
| 		if err := ctnr.AttachResize(sz); err != nil {
 | |
| 			if !errors.Is(err, define.ErrCtrStateInvalid) {
 | |
| 				utils.InternalServerError(w, fmt.Errorf("cannot resize container: %w", err))
 | |
| 			} else {
 | |
| 				utils.Error(w, http.StatusConflict, err)
 | |
| 			}
 | |
| 			return
 | |
| 		}
 | |
| 		// This is not a 204, even though we write nothing, for compatibility
 | |
| 		// reasons.
 | |
| 		status = http.StatusOK
 | |
| 	case strings.Contains(r.URL.Path, "/exec/"):
 | |
| 		name := mux.Vars(r)["id"]
 | |
| 		ctnr, err := runtime.GetExecSessionContainer(name)
 | |
| 		if err != nil {
 | |
| 			utils.SessionNotFound(w, name, err)
 | |
| 			return
 | |
| 		}
 | |
| 		if state, err := ctnr.State(); err != nil {
 | |
| 			utils.InternalServerError(w, fmt.Errorf("cannot obtain session container state: %w", err))
 | |
| 			return
 | |
| 		} else if state != define.ContainerStateRunning && !query.IgnoreNotRunning {
 | |
| 			utils.Error(w, http.StatusConflict, fmt.Errorf("container %q in wrong state %q", name, state.String()))
 | |
| 			return
 | |
| 		}
 | |
| 		if err := ctnr.ExecResize(name, sz); err != nil {
 | |
| 			if !errors.Is(err, define.ErrExecSessionStateInvalid) || !query.IgnoreNotRunning {
 | |
| 				utils.InternalServerError(w, fmt.Errorf("cannot resize session: %w", err))
 | |
| 				return
 | |
| 			}
 | |
| 		}
 | |
| 		// This is not a 204, even though we write nothing, for compatibility
 | |
| 		// reasons.
 | |
| 		status = http.StatusCreated
 | |
| 	}
 | |
| 	w.WriteHeader(status)
 | |
| }
 |