diff --git a/cmd/podman/containers/cp.go b/cmd/podman/containers/cp.go index 5231066a2e..18bd3b3943 100644 --- a/cmd/podman/containers/cp.go +++ b/cmd/podman/containers/cp.go @@ -1,3 +1,5 @@ +//go:build !remote + package containers import ( diff --git a/cmd/podman/images/build.go b/cmd/podman/images/build.go index f4657e4daa..89983b82a3 100644 --- a/cmd/podman/images/build.go +++ b/cmd/podman/images/build.go @@ -1,3 +1,5 @@ +//go:build !remote + package images import ( diff --git a/cmd/podman/images/version.go b/cmd/podman/images/version.go index eee2c039fe..6431f63c68 100644 --- a/cmd/podman/images/version.go +++ b/cmd/podman/images/version.go @@ -1,3 +1,5 @@ +//go:build !remote + package images import ( diff --git a/cmd/podman/utils/error.go b/cmd/podman/utils/error.go index aa477833b9..b3aab22589 100644 --- a/cmd/podman/utils/error.go +++ b/cmd/podman/utils/error.go @@ -5,10 +5,7 @@ import ( "fmt" "os" "os/exec" - "strconv" - "strings" - buildahCLI "github.com/containers/buildah/pkg/cli" "github.com/containers/podman/v4/cmd/podman/registry" ) @@ -25,29 +22,6 @@ func (o OutputErrors) PrintErrors() (lastError error) { return } -/* -For remote client, server does not returns error with exit code - - instead returns a message and we cast it to a new error. - - Following function performs parsing on build error and returns - exit status which was expected for this current build -*/ -func ExitCodeFromBuildError(errorMsg string) (int, error) { - if strings.Contains(errorMsg, "exit status") { - errorSplit := strings.Split(errorMsg, " ") - if errorSplit[len(errorSplit)-2] == "status" { - tmpSplit := strings.Split(errorSplit[len(errorSplit)-1], "\n") - exitCodeRemote, err := strconv.Atoi(tmpSplit[0]) - if err == nil { - return exitCodeRemote, nil - } - return buildahCLI.ExecErrorCodeGeneric, err - } - } - return buildahCLI.ExecErrorCodeGeneric, errors.New("message does not contains a valid exit code") -} - // HandleOSExecError checks the given error for an exec.ExitError error and // sets the same podman exit code as the error. // No error will be returned in this case to make sure things like podman diff --git a/cmd/podman/utils/error_local.go b/cmd/podman/utils/error_local.go new file mode 100644 index 0000000000..26923c44ea --- /dev/null +++ b/cmd/podman/utils/error_local.go @@ -0,0 +1,33 @@ +//go:build !remote + +package utils + +import ( + "errors" + "strconv" + "strings" + + buildahCLI "github.com/containers/buildah/pkg/cli" +) + +/* +For remote client, server does not returns error with exit code +instead returns a message and we cast it to a new error. + +Following function performs parsing on build error and returns +exit status which was expected for this current build +*/ +func ExitCodeFromBuildError(errorMsg string) (int, error) { + if strings.Contains(errorMsg, "exit status") { + errorSplit := strings.Split(errorMsg, " ") + if errorSplit[len(errorSplit)-2] == "status" { + tmpSplit := strings.Split(errorSplit[len(errorSplit)-1], "\n") + exitCodeRemote, err := strconv.Atoi(tmpSplit[0]) + if err == nil { + return exitCodeRemote, nil + } + return buildahCLI.ExecErrorCodeGeneric, err + } + } + return buildahCLI.ExecErrorCodeGeneric, errors.New("message does not contains a valid exit code") +} diff --git a/completions/bash/podman b/completions/bash/podman index 1980e5e795..141f562a25 100644 --- a/completions/bash/podman +++ b/completions/bash/podman @@ -2,7 +2,7 @@ __podman_debug() { - if [[ -n ${BASH_COMP_DEBUG_FILE:-} ]]; then + if [[ -n ${BASH_COMP_DEBUG_FILE-} ]]; then echo "$*" >> "${BASH_COMP_DEBUG_FILE}" fi } @@ -21,7 +21,7 @@ __podman_get_completion_results() { local requestComp lastParam lastChar args # Prepare the command to request completions for the program. - # Calling ${words[0]} instead of directly podman allows to handle aliases + # Calling ${words[0]} instead of directly podman allows handling aliases args=("${words[@]:1}") requestComp="${words[0]} __complete ${args[*]}" @@ -29,7 +29,7 @@ __podman_get_completion_results() { lastChar=${lastParam:$((${#lastParam}-1)):1} __podman_debug "lastParam ${lastParam}, lastChar ${lastChar}" - if [ -z "${cur}" ] && [ "${lastChar}" != "=" ]; then + if [[ -z ${cur} && ${lastChar} != = ]]; then # If the last parameter is complete (there is a space following it) # We add an extra empty parameter so we can indicate this to the go method. __podman_debug "Adding extra empty parameter" @@ -39,7 +39,7 @@ __podman_get_completion_results() { # When completing a flag with an = (e.g., podman -n=) # bash focuses on the part after the =, so we need to remove # the flag part from $cur - if [[ "${cur}" == -*=* ]]; then + if [[ ${cur} == -*=* ]]; then cur="${cur#*=}" fi @@ -51,7 +51,7 @@ __podman_get_completion_results() { directive=${out##*:} # Remove the directive out=${out%:*} - if [ "${directive}" = "${out}" ]; then + if [[ ${directive} == "${out}" ]]; then # There is not directive specified directive=0 fi @@ -65,22 +65,36 @@ __podman_process_completion_results() { local shellCompDirectiveNoFileComp=4 local shellCompDirectiveFilterFileExt=8 local shellCompDirectiveFilterDirs=16 + local shellCompDirectiveKeepOrder=32 - if [ $((directive & shellCompDirectiveError)) -ne 0 ]; then + if (((directive & shellCompDirectiveError) != 0)); then # Error code. No completion. __podman_debug "Received error from custom completion go code" return else - if [ $((directive & shellCompDirectiveNoSpace)) -ne 0 ]; then - if [[ $(type -t compopt) = "builtin" ]]; then + if (((directive & shellCompDirectiveNoSpace) != 0)); then + if [[ $(type -t compopt) == builtin ]]; then __podman_debug "Activating no space" compopt -o nospace else __podman_debug "No space directive not supported in this version of bash" fi fi - if [ $((directive & shellCompDirectiveNoFileComp)) -ne 0 ]; then - if [[ $(type -t compopt) = "builtin" ]]; then + if (((directive & shellCompDirectiveKeepOrder) != 0)); then + if [[ $(type -t compopt) == builtin ]]; then + # no sort isn't supported for bash less than < 4.4 + if [[ ${BASH_VERSINFO[0]} -lt 4 || ( ${BASH_VERSINFO[0]} -eq 4 && ${BASH_VERSINFO[1]} -lt 4 ) ]]; then + __podman_debug "No sort directive not supported in this version of bash" + else + __podman_debug "Activating keep order" + compopt -o nosort + fi + else + __podman_debug "No sort directive not supported in this version of bash" + fi + fi + if (((directive & shellCompDirectiveNoFileComp) != 0)); then + if [[ $(type -t compopt) == builtin ]]; then __podman_debug "Activating no file completion" compopt +o default else @@ -94,7 +108,7 @@ __podman_process_completion_results() { local activeHelp=() __podman_extract_activeHelp - if [ $((directive & shellCompDirectiveFilterFileExt)) -ne 0 ]; then + if (((directive & shellCompDirectiveFilterFileExt) != 0)); then # File extension filtering local fullFilter filter filteringCmd @@ -107,13 +121,12 @@ __podman_process_completion_results() { filteringCmd="_filedir $fullFilter" __podman_debug "File filtering command: $filteringCmd" $filteringCmd - elif [ $((directive & shellCompDirectiveFilterDirs)) -ne 0 ]; then + elif (((directive & shellCompDirectiveFilterDirs) != 0)); then # File completion for directories only - # Use printf to strip any trailing newline local subdir - subdir=$(printf "%s" "${completions[0]}") - if [ -n "$subdir" ]; then + subdir=${completions[0]} + if [[ -n $subdir ]]; then __podman_debug "Listing directories in $subdir" pushd "$subdir" >/dev/null 2>&1 && _filedir -d && popd >/dev/null 2>&1 || return else @@ -128,7 +141,7 @@ __podman_process_completion_results() { __podman_handle_special_char "$cur" = # Print the activeHelp statements before we finish - if [ ${#activeHelp[*]} -ne 0 ]; then + if ((${#activeHelp[*]} != 0)); then printf "\n"; printf "%s\n" "${activeHelp[@]}" printf "\n" @@ -152,17 +165,17 @@ __podman_extract_activeHelp() { local endIndex=${#activeHelpMarker} while IFS='' read -r comp; do - if [ "${comp:0:endIndex}" = "$activeHelpMarker" ]; then + if [[ ${comp:0:endIndex} == $activeHelpMarker ]]; then comp=${comp:endIndex} __podman_debug "ActiveHelp found: $comp" - if [ -n "$comp" ]; then + if [[ -n $comp ]]; then activeHelp+=("$comp") fi else # Not an activeHelp line but a normal completion completions+=("$comp") fi - done < <(printf "%s\n" "${out}") + done <<<"${out}" } __podman_handle_completion_types() { @@ -218,7 +231,7 @@ __podman_handle_standard_completion_case() { done < <(printf "%s\n" "${completions[@]}") # If there is a single completion left, remove the description text - if [ ${#COMPREPLY[*]} -eq 1 ]; then + if ((${#COMPREPLY[*]} == 1)); then __podman_debug "COMPREPLY[0]: ${COMPREPLY[0]}" comp="${COMPREPLY[0]%%$tab*}" __podman_debug "Removed description from single completion, which is now: ${comp}" @@ -235,8 +248,8 @@ __podman_handle_special_char() if [[ "$comp" == *${char}* && "$COMP_WORDBREAKS" == *${char}* ]]; then local word=${comp%"${comp##*${char}}"} local idx=${#COMPREPLY[*]} - while [[ $((--idx)) -ge 0 ]]; do - COMPREPLY[$idx]=${COMPREPLY[$idx]#"$word"} + while ((--idx >= 0)); do + COMPREPLY[idx]=${COMPREPLY[idx]#"$word"} done fi } @@ -262,7 +275,7 @@ __podman_format_comp_descriptions() # Make sure we can fit a description of at least 8 characters # if we are to align the descriptions. - if [[ $maxdesclength -gt 8 ]]; then + if ((maxdesclength > 8)); then # Add the proper number of spaces to align the descriptions for ((i = ${#comp} ; i < longest ; i++)); do comp+=" " @@ -274,8 +287,8 @@ __podman_format_comp_descriptions() # If there is enough space for any description text, # truncate the descriptions that are too long for the shell width - if [ $maxdesclength -gt 0 ]; then - if [ ${#desc} -gt $maxdesclength ]; then + if ((maxdesclength > 0)); then + if ((${#desc} > maxdesclength)); then desc=${desc:0:$(( maxdesclength - 1 ))} desc+="…" fi @@ -296,9 +309,9 @@ __start_podman() # Call _init_completion from the bash-completion package # to prepare the arguments properly if declare -F _init_completion >/dev/null 2>&1; then - _init_completion -n "=:" || return + _init_completion -n =: || return else - __podman_init_completion -n "=:" || return + __podman_init_completion -n =: || return fi __podman_debug diff --git a/completions/bash/podman-remote b/completions/bash/podman-remote index 9d32fc5692..9eb6f18574 100644 --- a/completions/bash/podman-remote +++ b/completions/bash/podman-remote @@ -2,7 +2,7 @@ __podman-remote_debug() { - if [[ -n ${BASH_COMP_DEBUG_FILE:-} ]]; then + if [[ -n ${BASH_COMP_DEBUG_FILE-} ]]; then echo "$*" >> "${BASH_COMP_DEBUG_FILE}" fi } @@ -21,7 +21,7 @@ __podman-remote_get_completion_results() { local requestComp lastParam lastChar args # Prepare the command to request completions for the program. - # Calling ${words[0]} instead of directly podman-remote allows to handle aliases + # Calling ${words[0]} instead of directly podman-remote allows handling aliases args=("${words[@]:1}") requestComp="${words[0]} __complete ${args[*]}" @@ -29,7 +29,7 @@ __podman-remote_get_completion_results() { lastChar=${lastParam:$((${#lastParam}-1)):1} __podman-remote_debug "lastParam ${lastParam}, lastChar ${lastChar}" - if [ -z "${cur}" ] && [ "${lastChar}" != "=" ]; then + if [[ -z ${cur} && ${lastChar} != = ]]; then # If the last parameter is complete (there is a space following it) # We add an extra empty parameter so we can indicate this to the go method. __podman-remote_debug "Adding extra empty parameter" @@ -39,7 +39,7 @@ __podman-remote_get_completion_results() { # When completing a flag with an = (e.g., podman-remote -n=) # bash focuses on the part after the =, so we need to remove # the flag part from $cur - if [[ "${cur}" == -*=* ]]; then + if [[ ${cur} == -*=* ]]; then cur="${cur#*=}" fi @@ -51,7 +51,7 @@ __podman-remote_get_completion_results() { directive=${out##*:} # Remove the directive out=${out%:*} - if [ "${directive}" = "${out}" ]; then + if [[ ${directive} == "${out}" ]]; then # There is not directive specified directive=0 fi @@ -65,22 +65,36 @@ __podman-remote_process_completion_results() { local shellCompDirectiveNoFileComp=4 local shellCompDirectiveFilterFileExt=8 local shellCompDirectiveFilterDirs=16 + local shellCompDirectiveKeepOrder=32 - if [ $((directive & shellCompDirectiveError)) -ne 0 ]; then + if (((directive & shellCompDirectiveError) != 0)); then # Error code. No completion. __podman-remote_debug "Received error from custom completion go code" return else - if [ $((directive & shellCompDirectiveNoSpace)) -ne 0 ]; then - if [[ $(type -t compopt) = "builtin" ]]; then + if (((directive & shellCompDirectiveNoSpace) != 0)); then + if [[ $(type -t compopt) == builtin ]]; then __podman-remote_debug "Activating no space" compopt -o nospace else __podman-remote_debug "No space directive not supported in this version of bash" fi fi - if [ $((directive & shellCompDirectiveNoFileComp)) -ne 0 ]; then - if [[ $(type -t compopt) = "builtin" ]]; then + if (((directive & shellCompDirectiveKeepOrder) != 0)); then + if [[ $(type -t compopt) == builtin ]]; then + # no sort isn't supported for bash less than < 4.4 + if [[ ${BASH_VERSINFO[0]} -lt 4 || ( ${BASH_VERSINFO[0]} -eq 4 && ${BASH_VERSINFO[1]} -lt 4 ) ]]; then + __podman-remote_debug "No sort directive not supported in this version of bash" + else + __podman-remote_debug "Activating keep order" + compopt -o nosort + fi + else + __podman-remote_debug "No sort directive not supported in this version of bash" + fi + fi + if (((directive & shellCompDirectiveNoFileComp) != 0)); then + if [[ $(type -t compopt) == builtin ]]; then __podman-remote_debug "Activating no file completion" compopt +o default else @@ -94,7 +108,7 @@ __podman-remote_process_completion_results() { local activeHelp=() __podman-remote_extract_activeHelp - if [ $((directive & shellCompDirectiveFilterFileExt)) -ne 0 ]; then + if (((directive & shellCompDirectiveFilterFileExt) != 0)); then # File extension filtering local fullFilter filter filteringCmd @@ -107,13 +121,12 @@ __podman-remote_process_completion_results() { filteringCmd="_filedir $fullFilter" __podman-remote_debug "File filtering command: $filteringCmd" $filteringCmd - elif [ $((directive & shellCompDirectiveFilterDirs)) -ne 0 ]; then + elif (((directive & shellCompDirectiveFilterDirs) != 0)); then # File completion for directories only - # Use printf to strip any trailing newline local subdir - subdir=$(printf "%s" "${completions[0]}") - if [ -n "$subdir" ]; then + subdir=${completions[0]} + if [[ -n $subdir ]]; then __podman-remote_debug "Listing directories in $subdir" pushd "$subdir" >/dev/null 2>&1 && _filedir -d && popd >/dev/null 2>&1 || return else @@ -128,7 +141,7 @@ __podman-remote_process_completion_results() { __podman-remote_handle_special_char "$cur" = # Print the activeHelp statements before we finish - if [ ${#activeHelp[*]} -ne 0 ]; then + if ((${#activeHelp[*]} != 0)); then printf "\n"; printf "%s\n" "${activeHelp[@]}" printf "\n" @@ -152,17 +165,17 @@ __podman-remote_extract_activeHelp() { local endIndex=${#activeHelpMarker} while IFS='' read -r comp; do - if [ "${comp:0:endIndex}" = "$activeHelpMarker" ]; then + if [[ ${comp:0:endIndex} == $activeHelpMarker ]]; then comp=${comp:endIndex} __podman-remote_debug "ActiveHelp found: $comp" - if [ -n "$comp" ]; then + if [[ -n $comp ]]; then activeHelp+=("$comp") fi else # Not an activeHelp line but a normal completion completions+=("$comp") fi - done < <(printf "%s\n" "${out}") + done <<<"${out}" } __podman-remote_handle_completion_types() { @@ -218,7 +231,7 @@ __podman-remote_handle_standard_completion_case() { done < <(printf "%s\n" "${completions[@]}") # If there is a single completion left, remove the description text - if [ ${#COMPREPLY[*]} -eq 1 ]; then + if ((${#COMPREPLY[*]} == 1)); then __podman-remote_debug "COMPREPLY[0]: ${COMPREPLY[0]}" comp="${COMPREPLY[0]%%$tab*}" __podman-remote_debug "Removed description from single completion, which is now: ${comp}" @@ -235,8 +248,8 @@ __podman-remote_handle_special_char() if [[ "$comp" == *${char}* && "$COMP_WORDBREAKS" == *${char}* ]]; then local word=${comp%"${comp##*${char}}"} local idx=${#COMPREPLY[*]} - while [[ $((--idx)) -ge 0 ]]; do - COMPREPLY[$idx]=${COMPREPLY[$idx]#"$word"} + while ((--idx >= 0)); do + COMPREPLY[idx]=${COMPREPLY[idx]#"$word"} done fi } @@ -262,7 +275,7 @@ __podman-remote_format_comp_descriptions() # Make sure we can fit a description of at least 8 characters # if we are to align the descriptions. - if [[ $maxdesclength -gt 8 ]]; then + if ((maxdesclength > 8)); then # Add the proper number of spaces to align the descriptions for ((i = ${#comp} ; i < longest ; i++)); do comp+=" " @@ -274,8 +287,8 @@ __podman-remote_format_comp_descriptions() # If there is enough space for any description text, # truncate the descriptions that are too long for the shell width - if [ $maxdesclength -gt 0 ]; then - if [ ${#desc} -gt $maxdesclength ]; then + if ((maxdesclength > 0)); then + if ((${#desc} > maxdesclength)); then desc=${desc:0:$(( maxdesclength - 1 ))} desc+="…" fi @@ -296,9 +309,9 @@ __start_podman-remote() # Call _init_completion from the bash-completion package # to prepare the arguments properly if declare -F _init_completion >/dev/null 2>&1; then - _init_completion -n "=:" || return + _init_completion -n =: || return else - __podman-remote_init_completion -n "=:" || return + __podman-remote_init_completion -n =: || return fi __podman-remote_debug diff --git a/completions/fish/podman-remote.fish b/completions/fish/podman-remote.fish index 67c9641335..471ffe8b1c 100644 --- a/completions/fish/podman-remote.fish +++ b/completions/fish/podman-remote.fish @@ -55,6 +55,60 @@ function __podman_remote_perform_completion printf "%s\n" "$directiveLine" end +# this function limits calls to __podman_remote_perform_completion, by caching the result behind $__podman_remote_perform_completion_once_result +function __podman_remote_perform_completion_once + __podman_remote_debug "Starting __podman_remote_perform_completion_once" + + if test -n "$__podman_remote_perform_completion_once_result" + __podman_remote_debug "Seems like a valid result already exists, skipping __podman_remote_perform_completion" + return 0 + end + + set --global __podman_remote_perform_completion_once_result (__podman_remote_perform_completion) + if test -z "$__podman_remote_perform_completion_once_result" + __podman_remote_debug "No completions, probably due to a failure" + return 1 + end + + __podman_remote_debug "Performed completions and set __podman_remote_perform_completion_once_result" + return 0 +end + +# this function is used to clear the $__podman_remote_perform_completion_once_result variable after completions are run +function __podman_remote_clear_perform_completion_once_result + __podman_remote_debug "" + __podman_remote_debug "========= clearing previously set __podman_remote_perform_completion_once_result variable ==========" + set --erase __podman_remote_perform_completion_once_result + __podman_remote_debug "Successfully erased the variable __podman_remote_perform_completion_once_result" +end + +function __podman_remote_requires_order_preservation + __podman_remote_debug "" + __podman_remote_debug "========= checking if order preservation is required ==========" + + __podman_remote_perform_completion_once + if test -z "$__podman_remote_perform_completion_once_result" + __podman_remote_debug "Error determining if order preservation is required" + return 1 + end + + set -l directive (string sub --start 2 $__podman_remote_perform_completion_once_result[-1]) + __podman_remote_debug "Directive is: $directive" + + set -l shellCompDirectiveKeepOrder 32 + set -l keeporder (math (math --scale 0 $directive / $shellCompDirectiveKeepOrder) % 2) + __podman_remote_debug "Keeporder is: $keeporder" + + if test $keeporder -ne 0 + __podman_remote_debug "This does require order preservation" + return 0 + end + + __podman_remote_debug "This doesn't require order preservation" + return 1 +end + + # This function does two things: # - Obtain the completions and store them in the global __podman_remote_comp_results # - Return false if file completion should be performed @@ -65,17 +119,17 @@ function __podman_remote_prepare_completions # Start fresh set --erase __podman_remote_comp_results - set -l results (__podman_remote_perform_completion) - __podman_remote_debug "Completion results: $results" + __podman_remote_perform_completion_once + __podman_remote_debug "Completion results: $__podman_remote_perform_completion_once_result" - if test -z "$results" + if test -z "$__podman_remote_perform_completion_once_result" __podman_remote_debug "No completion, probably due to a failure" # Might as well do file completion, in case it helps return 1 end - set -l directive (string sub --start 2 $results[-1]) - set --global __podman_remote_comp_results $results[1..-2] + set -l directive (string sub --start 2 $__podman_remote_perform_completion_once_result[-1]) + set --global __podman_remote_comp_results $__podman_remote_perform_completion_once_result[1..-2] __podman_remote_debug "Completions are: $__podman_remote_comp_results" __podman_remote_debug "Directive is: $directive" @@ -171,9 +225,13 @@ end # Remove any pre-existing completions for the program since we will be handling all of them. complete -c podman-remote -e +# this will get called after the two calls below and clear the $__podman_remote_perform_completion_once_result global +complete -c podman-remote -n '__podman_remote_clear_perform_completion_once_result' # The call to __podman_remote_prepare_completions will setup __podman_remote_comp_results # which provides the program's completion choices. -complete -c podman-remote -n '__podman_remote_prepare_completions' -f -a '$__podman_remote_comp_results' - +# If this doesn't require order preservation, we don't use the -k flag +complete -c podman-remote -n 'not __podman_remote_requires_order_preservation && __podman_remote_prepare_completions' -f -a '$__podman_remote_comp_results' +# otherwise we use the -k flag +complete -k -c podman-remote -n '__podman_remote_requires_order_preservation && __podman_remote_prepare_completions' -f -a '$__podman_remote_comp_results' # This file is generated with "podman-remote completion"; see: podman-completion(1) diff --git a/completions/fish/podman.fish b/completions/fish/podman.fish index be18c45cd0..2728a499a8 100644 --- a/completions/fish/podman.fish +++ b/completions/fish/podman.fish @@ -55,6 +55,60 @@ function __podman_perform_completion printf "%s\n" "$directiveLine" end +# this function limits calls to __podman_perform_completion, by caching the result behind $__podman_perform_completion_once_result +function __podman_perform_completion_once + __podman_debug "Starting __podman_perform_completion_once" + + if test -n "$__podman_perform_completion_once_result" + __podman_debug "Seems like a valid result already exists, skipping __podman_perform_completion" + return 0 + end + + set --global __podman_perform_completion_once_result (__podman_perform_completion) + if test -z "$__podman_perform_completion_once_result" + __podman_debug "No completions, probably due to a failure" + return 1 + end + + __podman_debug "Performed completions and set __podman_perform_completion_once_result" + return 0 +end + +# this function is used to clear the $__podman_perform_completion_once_result variable after completions are run +function __podman_clear_perform_completion_once_result + __podman_debug "" + __podman_debug "========= clearing previously set __podman_perform_completion_once_result variable ==========" + set --erase __podman_perform_completion_once_result + __podman_debug "Successfully erased the variable __podman_perform_completion_once_result" +end + +function __podman_requires_order_preservation + __podman_debug "" + __podman_debug "========= checking if order preservation is required ==========" + + __podman_perform_completion_once + if test -z "$__podman_perform_completion_once_result" + __podman_debug "Error determining if order preservation is required" + return 1 + end + + set -l directive (string sub --start 2 $__podman_perform_completion_once_result[-1]) + __podman_debug "Directive is: $directive" + + set -l shellCompDirectiveKeepOrder 32 + set -l keeporder (math (math --scale 0 $directive / $shellCompDirectiveKeepOrder) % 2) + __podman_debug "Keeporder is: $keeporder" + + if test $keeporder -ne 0 + __podman_debug "This does require order preservation" + return 0 + end + + __podman_debug "This doesn't require order preservation" + return 1 +end + + # This function does two things: # - Obtain the completions and store them in the global __podman_comp_results # - Return false if file completion should be performed @@ -65,17 +119,17 @@ function __podman_prepare_completions # Start fresh set --erase __podman_comp_results - set -l results (__podman_perform_completion) - __podman_debug "Completion results: $results" + __podman_perform_completion_once + __podman_debug "Completion results: $__podman_perform_completion_once_result" - if test -z "$results" + if test -z "$__podman_perform_completion_once_result" __podman_debug "No completion, probably due to a failure" # Might as well do file completion, in case it helps return 1 end - set -l directive (string sub --start 2 $results[-1]) - set --global __podman_comp_results $results[1..-2] + set -l directive (string sub --start 2 $__podman_perform_completion_once_result[-1]) + set --global __podman_comp_results $__podman_perform_completion_once_result[1..-2] __podman_debug "Completions are: $__podman_comp_results" __podman_debug "Directive is: $directive" @@ -171,9 +225,13 @@ end # Remove any pre-existing completions for the program since we will be handling all of them. complete -c podman -e +# this will get called after the two calls below and clear the $__podman_perform_completion_once_result global +complete -c podman -n '__podman_clear_perform_completion_once_result' # The call to __podman_prepare_completions will setup __podman_comp_results # which provides the program's completion choices. -complete -c podman -n '__podman_prepare_completions' -f -a '$__podman_comp_results' - +# If this doesn't require order preservation, we don't use the -k flag +complete -c podman -n 'not __podman_requires_order_preservation && __podman_prepare_completions' -f -a '$__podman_comp_results' +# otherwise we use the -k flag +complete -k -c podman -n '__podman_requires_order_preservation && __podman_prepare_completions' -f -a '$__podman_comp_results' # This file is generated with "podman completion"; see: podman-completion(1) diff --git a/completions/powershell/podman-remote.ps1 b/completions/powershell/podman-remote.ps1 index f8a8d32390..0fe1809642 100644 --- a/completions/powershell/podman-remote.ps1 +++ b/completions/powershell/podman-remote.ps1 @@ -10,7 +10,7 @@ filter __podman-remote_escapeStringWithSpecialChars { $_ -replace '\s|#|@|\$|;|,|''|\{|\}|\(|\)|"|`|\||<|>|&','`$&' } -[scriptblock]$__podman_remoteCompleterBlock = { +[scriptblock]${__podman_remoteCompleterBlock} = { param( $WordToComplete, $CommandAst, @@ -40,6 +40,7 @@ filter __podman-remote_escapeStringWithSpecialChars { $ShellCompDirectiveNoFileComp=4 $ShellCompDirectiveFilterFileExt=8 $ShellCompDirectiveFilterDirs=16 + $ShellCompDirectiveKeepOrder=32 # Prepare the command to request completions for the program. # Split the command at the first space to separate the program and arguments. @@ -69,13 +70,22 @@ filter __podman-remote_escapeStringWithSpecialChars { # If the last parameter is complete (there is a space following it) # We add an extra empty parameter so we can indicate this to the go method. __podman-remote_debug "Adding extra empty parameter" - # We need to use `"`" to pass an empty argument a "" or '' does not work!!! - $RequestComp="$RequestComp" + ' `"`"' + # PowerShell 7.2+ changed the way how the arguments are passed to executables, + # so for pre-7.2 or when Legacy argument passing is enabled we need to use + # `"`" to pass an empty argument, a "" or '' does not work!!! + if ($PSVersionTable.PsVersion -lt [version]'7.2.0' -or + ($PSVersionTable.PsVersion -lt [version]'7.3.0' -and -not [ExperimentalFeature]::IsEnabled("PSNativeCommandArgumentPassing")) -or + (($PSVersionTable.PsVersion -ge [version]'7.3.0' -or [ExperimentalFeature]::IsEnabled("PSNativeCommandArgumentPassing")) -and + $PSNativeCommandArgumentPassing -eq 'Legacy')) { + $RequestComp="$RequestComp" + ' `"`"' + } else { + $RequestComp="$RequestComp" + ' ""' + } } __podman-remote_debug "Calling $RequestComp" # First disable ActiveHelp which is not supported for Powershell - $env:PODMAN_REMOTE_ACTIVE_HELP=0 + ${env:PODMAN_REMOTE_ACTIVE_HELP}=0 #call the command store the output in $out and redirect stderr and stdout to null # $Out is an array contains each line per element @@ -100,7 +110,7 @@ filter __podman-remote_escapeStringWithSpecialChars { } $Longest = 0 - $Values = $Out | ForEach-Object { + [Array]$Values = $Out | ForEach-Object { #Split the output in name and description $Name, $Description = $_.Split("`t",2) __podman-remote_debug "Name: $Name Description: $Description" @@ -145,6 +155,11 @@ filter __podman-remote_escapeStringWithSpecialChars { } } + # we sort the values in ascending order by name if keep order isn't passed + if (($Directive -band $ShellCompDirectiveKeepOrder) -eq 0 ) { + $Values = $Values | Sort-Object -Property Name + } + if (($Directive -band $ShellCompDirectiveNoFileComp) -ne 0 ) { __podman-remote_debug "ShellCompDirectiveNoFileComp is called" @@ -227,6 +242,6 @@ filter __podman-remote_escapeStringWithSpecialChars { } } -Register-ArgumentCompleter -CommandName 'podman-remote' -ScriptBlock $__podman_remoteCompleterBlock +Register-ArgumentCompleter -CommandName 'podman-remote' -ScriptBlock ${__podman_remoteCompleterBlock} # This file is generated with "podman-remote completion"; see: podman-completion(1) diff --git a/completions/powershell/podman.ps1 b/completions/powershell/podman.ps1 index ff5ec158c0..118af7af6c 100644 --- a/completions/powershell/podman.ps1 +++ b/completions/powershell/podman.ps1 @@ -10,7 +10,7 @@ filter __podman_escapeStringWithSpecialChars { $_ -replace '\s|#|@|\$|;|,|''|\{|\}|\(|\)|"|`|\||<|>|&','`$&' } -[scriptblock]$__podmanCompleterBlock = { +[scriptblock]${__podmanCompleterBlock} = { param( $WordToComplete, $CommandAst, @@ -40,6 +40,7 @@ filter __podman_escapeStringWithSpecialChars { $ShellCompDirectiveNoFileComp=4 $ShellCompDirectiveFilterFileExt=8 $ShellCompDirectiveFilterDirs=16 + $ShellCompDirectiveKeepOrder=32 # Prepare the command to request completions for the program. # Split the command at the first space to separate the program and arguments. @@ -69,13 +70,22 @@ filter __podman_escapeStringWithSpecialChars { # If the last parameter is complete (there is a space following it) # We add an extra empty parameter so we can indicate this to the go method. __podman_debug "Adding extra empty parameter" - # We need to use `"`" to pass an empty argument a "" or '' does not work!!! - $RequestComp="$RequestComp" + ' `"`"' + # PowerShell 7.2+ changed the way how the arguments are passed to executables, + # so for pre-7.2 or when Legacy argument passing is enabled we need to use + # `"`" to pass an empty argument, a "" or '' does not work!!! + if ($PSVersionTable.PsVersion -lt [version]'7.2.0' -or + ($PSVersionTable.PsVersion -lt [version]'7.3.0' -and -not [ExperimentalFeature]::IsEnabled("PSNativeCommandArgumentPassing")) -or + (($PSVersionTable.PsVersion -ge [version]'7.3.0' -or [ExperimentalFeature]::IsEnabled("PSNativeCommandArgumentPassing")) -and + $PSNativeCommandArgumentPassing -eq 'Legacy')) { + $RequestComp="$RequestComp" + ' `"`"' + } else { + $RequestComp="$RequestComp" + ' ""' + } } __podman_debug "Calling $RequestComp" # First disable ActiveHelp which is not supported for Powershell - $env:PODMAN_ACTIVE_HELP=0 + ${env:PODMAN_ACTIVE_HELP}=0 #call the command store the output in $out and redirect stderr and stdout to null # $Out is an array contains each line per element @@ -100,7 +110,7 @@ filter __podman_escapeStringWithSpecialChars { } $Longest = 0 - $Values = $Out | ForEach-Object { + [Array]$Values = $Out | ForEach-Object { #Split the output in name and description $Name, $Description = $_.Split("`t",2) __podman_debug "Name: $Name Description: $Description" @@ -145,6 +155,11 @@ filter __podman_escapeStringWithSpecialChars { } } + # we sort the values in ascending order by name if keep order isn't passed + if (($Directive -band $ShellCompDirectiveKeepOrder) -eq 0 ) { + $Values = $Values | Sort-Object -Property Name + } + if (($Directive -band $ShellCompDirectiveNoFileComp) -ne 0 ) { __podman_debug "ShellCompDirectiveNoFileComp is called" @@ -227,6 +242,6 @@ filter __podman_escapeStringWithSpecialChars { } } -Register-ArgumentCompleter -CommandName 'podman' -ScriptBlock $__podmanCompleterBlock +Register-ArgumentCompleter -CommandName 'podman' -ScriptBlock ${__podmanCompleterBlock} # This file is generated with "podman completion"; see: podman-completion(1) diff --git a/completions/zsh/_podman b/completions/zsh/_podman index e2d086108e..fdd843d89b 100644 --- a/completions/zsh/_podman +++ b/completions/zsh/_podman @@ -1,4 +1,5 @@ #compdef podman +compdef _podman podman # zsh completion for podman -*- shell-script -*- @@ -17,8 +18,9 @@ _podman() local shellCompDirectiveNoFileComp=4 local shellCompDirectiveFilterFileExt=8 local shellCompDirectiveFilterDirs=16 + local shellCompDirectiveKeepOrder=32 - local lastParam lastChar flagPrefix requestComp out directive comp lastComp noSpace + local lastParam lastChar flagPrefix requestComp out directive comp lastComp noSpace keepOrder local -a completions __podman_debug "\n========= starting completion logic ==========" @@ -136,6 +138,11 @@ _podman() noSpace="-S ''" fi + if [ $((directive & shellCompDirectiveKeepOrder)) -ne 0 ]; then + __podman_debug "Activating keep order." + keepOrder="-V" + fi + if [ $((directive & shellCompDirectiveFilterFileExt)) -ne 0 ]; then # File extension filtering local filteringCmd @@ -171,7 +178,7 @@ _podman() return $result else __podman_debug "Calling _describe" - if eval _describe "completions" completions $flagPrefix $noSpace; then + if eval _describe $keepOrder "completions" completions $flagPrefix $noSpace; then __podman_debug "_describe found some completions" # Return the success of having called _describe diff --git a/completions/zsh/_podman-remote b/completions/zsh/_podman-remote index 2d7e7a5494..532adf6308 100644 --- a/completions/zsh/_podman-remote +++ b/completions/zsh/_podman-remote @@ -1,4 +1,5 @@ #compdef podman-remote +compdef _podman-remote podman-remote # zsh completion for podman-remote -*- shell-script -*- @@ -17,8 +18,9 @@ _podman-remote() local shellCompDirectiveNoFileComp=4 local shellCompDirectiveFilterFileExt=8 local shellCompDirectiveFilterDirs=16 + local shellCompDirectiveKeepOrder=32 - local lastParam lastChar flagPrefix requestComp out directive comp lastComp noSpace + local lastParam lastChar flagPrefix requestComp out directive comp lastComp noSpace keepOrder local -a completions __podman-remote_debug "\n========= starting completion logic ==========" @@ -136,6 +138,11 @@ _podman-remote() noSpace="-S ''" fi + if [ $((directive & shellCompDirectiveKeepOrder)) -ne 0 ]; then + __podman-remote_debug "Activating keep order." + keepOrder="-V" + fi + if [ $((directive & shellCompDirectiveFilterFileExt)) -ne 0 ]; then # File extension filtering local filteringCmd @@ -171,7 +178,7 @@ _podman-remote() return $result else __podman-remote_debug "Calling _describe" - if eval _describe "completions" completions $flagPrefix $noSpace; then + if eval _describe $keepOrder "completions" completions $flagPrefix $noSpace; then __podman-remote_debug "_describe found some completions" # Return the success of having called _describe diff --git a/pkg/api/handlers/compat/images.go b/pkg/api/handlers/compat/images.go index 34f721a882..4ec3921f0c 100644 --- a/pkg/api/handlers/compat/images.go +++ b/pkg/api/handlers/compat/images.go @@ -1,3 +1,5 @@ +//go:build !remote + package compat import ( diff --git a/pkg/api/handlers/compat/images_tag.go b/pkg/api/handlers/compat/images_tag.go index e9f6dedd06..690f465b1a 100644 --- a/pkg/api/handlers/compat/images_tag.go +++ b/pkg/api/handlers/compat/images_tag.go @@ -1,3 +1,5 @@ +//go:build !remote + package compat import ( diff --git a/pkg/api/handlers/libpod/images.go b/pkg/api/handlers/libpod/images.go index 412532954b..6bbedaa548 100644 --- a/pkg/api/handlers/libpod/images.go +++ b/pkg/api/handlers/libpod/images.go @@ -1,3 +1,5 @@ +//go:build !remote + package libpod import ( diff --git a/pkg/api/handlers/libpod/images_pull.go b/pkg/api/handlers/libpod/images_pull.go index 57b2e3a787..1c3b26f56f 100644 --- a/pkg/api/handlers/libpod/images_pull.go +++ b/pkg/api/handlers/libpod/images_pull.go @@ -1,3 +1,5 @@ +//go:build !remote + package libpod import ( diff --git a/pkg/api/handlers/types.go b/pkg/api/handlers/types.go index bb416d9f41..b8059bafb1 100644 --- a/pkg/api/handlers/types.go +++ b/pkg/api/handlers/types.go @@ -1,16 +1,10 @@ package handlers import ( - "context" - "fmt" - "time" - - "github.com/containers/common/libimage" "github.com/containers/podman/v4/pkg/domain/entities" docker "github.com/docker/docker/api/types" dockerContainer "github.com/docker/docker/api/types/container" dockerNetwork "github.com/docker/docker/api/types/network" - "github.com/docker/go-connections/nat" "github.com/opencontainers/runtime-spec/specs-go" ) @@ -167,96 +161,3 @@ type ExecStartConfig struct { Height uint16 `json:"h"` Width uint16 `json:"w"` } - -func ImageDataToImageInspect(ctx context.Context, l *libimage.Image) (*ImageInspect, error) { - options := &libimage.InspectOptions{WithParent: true, WithSize: true} - info, err := l.Inspect(ctx, options) - if err != nil { - return nil, err - } - ports, err := portsToPortSet(info.Config.ExposedPorts) - if err != nil { - return nil, err - } - - // TODO: many fields in Config still need wiring - config := dockerContainer.Config{ - User: info.User, - ExposedPorts: ports, - Env: info.Config.Env, - Cmd: info.Config.Cmd, - Volumes: info.Config.Volumes, - WorkingDir: info.Config.WorkingDir, - Entrypoint: info.Config.Entrypoint, - Labels: info.Labels, - StopSignal: info.Config.StopSignal, - } - - rootfs := docker.RootFS{} - if info.RootFS != nil { - rootfs.Type = info.RootFS.Type - rootfs.Layers = make([]string, 0, len(info.RootFS.Layers)) - for _, layer := range info.RootFS.Layers { - rootfs.Layers = append(rootfs.Layers, string(layer)) - } - } - - graphDriver := docker.GraphDriverData{ - Name: info.GraphDriver.Name, - Data: info.GraphDriver.Data, - } - // Add in basic ContainerConfig to satisfy docker-compose - cc := new(dockerContainer.Config) - cc.Hostname = info.ID[0:11] // short ID is the hostname - cc.Volumes = info.Config.Volumes - - dockerImageInspect := docker.ImageInspect{ - Architecture: info.Architecture, - Author: info.Author, - Comment: info.Comment, - Config: &config, - ContainerConfig: cc, - Created: l.Created().Format(time.RFC3339Nano), - DockerVersion: info.Version, - GraphDriver: graphDriver, - ID: "sha256:" + l.ID(), - Metadata: docker.ImageMetadata{}, - Os: info.Os, - OsVersion: info.Version, - Parent: info.Parent, - RepoDigests: info.RepoDigests, - RepoTags: info.RepoTags, - RootFS: rootfs, - Size: info.Size, - Variant: "", - VirtualSize: info.VirtualSize, - } - return &ImageInspect{dockerImageInspect}, nil -} - -// portsToPortSet converts libpod's exposed ports to docker's structs -func portsToPortSet(input map[string]struct{}) (nat.PortSet, error) { - ports := make(nat.PortSet) - for k := range input { - proto, port := nat.SplitProtoPort(k) - switch proto { - // See the OCI image spec for details: - // https://github.com/opencontainers/image-spec/blob/e562b04403929d582d449ae5386ff79dd7961a11/config.md#properties - case "tcp", "": - p, err := nat.NewPort("tcp", port) - if err != nil { - return nil, fmt.Errorf("unable to create tcp port from %s: %w", k, err) - } - ports[p] = struct{}{} - case "udp": - p, err := nat.NewPort("udp", port) - if err != nil { - return nil, fmt.Errorf("unable to create tcp port from %s: %w", k, err) - } - ports[p] = struct{}{} - default: - return nil, fmt.Errorf("invalid port proto %q in %q", proto, k) - } - } - return ports, nil -} diff --git a/pkg/api/handlers/types_local.go b/pkg/api/handlers/types_local.go new file mode 100644 index 0000000000..7228c8da8a --- /dev/null +++ b/pkg/api/handlers/types_local.go @@ -0,0 +1,107 @@ +//go:build !remote + +package handlers + +import ( + "context" + "fmt" + "time" + + "github.com/containers/common/libimage" + docker "github.com/docker/docker/api/types" + dockerContainer "github.com/docker/docker/api/types/container" + "github.com/docker/go-connections/nat" +) + +func ImageDataToImageInspect(ctx context.Context, l *libimage.Image) (*ImageInspect, error) { + options := &libimage.InspectOptions{WithParent: true, WithSize: true} + info, err := l.Inspect(ctx, options) + if err != nil { + return nil, err + } + ports, err := portsToPortSet(info.Config.ExposedPorts) + if err != nil { + return nil, err + } + + // TODO: many fields in Config still need wiring + config := dockerContainer.Config{ + User: info.User, + ExposedPorts: ports, + Env: info.Config.Env, + Cmd: info.Config.Cmd, + Volumes: info.Config.Volumes, + WorkingDir: info.Config.WorkingDir, + Entrypoint: info.Config.Entrypoint, + Labels: info.Labels, + StopSignal: info.Config.StopSignal, + } + + rootfs := docker.RootFS{} + if info.RootFS != nil { + rootfs.Type = info.RootFS.Type + rootfs.Layers = make([]string, 0, len(info.RootFS.Layers)) + for _, layer := range info.RootFS.Layers { + rootfs.Layers = append(rootfs.Layers, string(layer)) + } + } + + graphDriver := docker.GraphDriverData{ + Name: info.GraphDriver.Name, + Data: info.GraphDriver.Data, + } + // Add in basic ContainerConfig to satisfy docker-compose + cc := new(dockerContainer.Config) + cc.Hostname = info.ID[0:11] // short ID is the hostname + cc.Volumes = info.Config.Volumes + + dockerImageInspect := docker.ImageInspect{ + Architecture: info.Architecture, + Author: info.Author, + Comment: info.Comment, + Config: &config, + ContainerConfig: cc, + Created: l.Created().Format(time.RFC3339Nano), + DockerVersion: info.Version, + GraphDriver: graphDriver, + ID: "sha256:" + l.ID(), + Metadata: docker.ImageMetadata{}, + Os: info.Os, + OsVersion: info.Version, + Parent: info.Parent, + RepoDigests: info.RepoDigests, + RepoTags: info.RepoTags, + RootFS: rootfs, + Size: info.Size, + Variant: "", + VirtualSize: info.VirtualSize, + } + return &ImageInspect{dockerImageInspect}, nil +} + +// portsToPortSet converts libpod's exposed ports to docker's structs +func portsToPortSet(input map[string]struct{}) (nat.PortSet, error) { + ports := make(nat.PortSet) + for k := range input { + proto, port := nat.SplitProtoPort(k) + switch proto { + // See the OCI image spec for details: + // https://github.com/opencontainers/image-spec/blob/e562b04403929d582d449ae5386ff79dd7961a11/config.md#properties + case "tcp", "": + p, err := nat.NewPort("tcp", port) + if err != nil { + return nil, fmt.Errorf("unable to create tcp port from %s: %w", k, err) + } + ports[p] = struct{}{} + case "udp": + p, err := nat.NewPort("udp", port) + if err != nil { + return nil, fmt.Errorf("unable to create tcp port from %s: %w", k, err) + } + ports[p] = struct{}{} + default: + return nil, fmt.Errorf("invalid port proto %q in %q", proto, k) + } + } + return ports, nil +} diff --git a/pkg/api/handlers/utils/images.go b/pkg/api/handlers/utils/images.go index 7831718cdb..b2906c1a79 100644 --- a/pkg/api/handlers/utils/images.go +++ b/pkg/api/handlers/utils/images.go @@ -1,3 +1,5 @@ +//go:build !remote + package utils import ( diff --git a/pkg/autoupdate/autoupdate.go b/pkg/autoupdate/autoupdate.go index 68a0fd7b6e..6aa47f46cd 100644 --- a/pkg/autoupdate/autoupdate.go +++ b/pkg/autoupdate/autoupdate.go @@ -1,3 +1,5 @@ +//go:build !remote + package autoupdate import ( diff --git a/pkg/checkpoint/checkpoint_restore.go b/pkg/checkpoint/checkpoint_restore.go index f461363551..b24aa5d846 100644 --- a/pkg/checkpoint/checkpoint_restore.go +++ b/pkg/checkpoint/checkpoint_restore.go @@ -1,3 +1,5 @@ +//go:build !remote + package checkpoint import ( diff --git a/pkg/domain/infra/abi/containers_runlabel.go b/pkg/domain/infra/abi/containers_runlabel.go index 463988c87e..8a194e0bd3 100644 --- a/pkg/domain/infra/abi/containers_runlabel.go +++ b/pkg/domain/infra/abi/containers_runlabel.go @@ -1,3 +1,5 @@ +//go:build !remote + package abi import ( diff --git a/pkg/domain/infra/abi/images.go b/pkg/domain/infra/abi/images.go index 54bb5be6cb..93581a33dd 100644 --- a/pkg/domain/infra/abi/images.go +++ b/pkg/domain/infra/abi/images.go @@ -1,3 +1,5 @@ +//go:build !remote + package abi import ( diff --git a/pkg/domain/infra/abi/images_list.go b/pkg/domain/infra/abi/images_list.go index 4788ecef92..838541b1df 100644 --- a/pkg/domain/infra/abi/images_list.go +++ b/pkg/domain/infra/abi/images_list.go @@ -1,3 +1,5 @@ +//go:build !remote + package abi import ( diff --git a/pkg/domain/infra/abi/manifest.go b/pkg/domain/infra/abi/manifest.go index 1c894891be..a093a121c2 100644 --- a/pkg/domain/infra/abi/manifest.go +++ b/pkg/domain/infra/abi/manifest.go @@ -1,3 +1,5 @@ +//go:build !remote + package abi import ( diff --git a/pkg/domain/infra/abi/play.go b/pkg/domain/infra/abi/play.go index 61bbd1ff15..1e71d62b5c 100644 --- a/pkg/domain/infra/abi/play.go +++ b/pkg/domain/infra/abi/play.go @@ -1,3 +1,5 @@ +//go:build !remote + package abi import ( diff --git a/pkg/specgen/config_unsupported.go b/pkg/specgen/config_unsupported.go index becfd2eafd..b288d1c26e 100644 --- a/pkg/specgen/config_unsupported.go +++ b/pkg/specgen/config_unsupported.go @@ -1,5 +1,5 @@ -//go:build !linux -// +build !linux +//go:build !linux && !remote +// +build !linux,!remote package specgen diff --git a/pkg/specgen/generate/config_linux_cgo.go b/pkg/specgen/generate/config_linux_cgo.go index 6903ccb511..62657afd1a 100644 --- a/pkg/specgen/generate/config_linux_cgo.go +++ b/pkg/specgen/generate/config_linux_cgo.go @@ -1,5 +1,5 @@ -//go:build linux && cgo -// +build linux,cgo +//go:build linux && cgo && !remote +// +build linux,cgo,!remote package generate diff --git a/pkg/specgen/generate/config_linux_nocgo.go b/pkg/specgen/generate/config_linux_nocgo.go index 99b0c4eb24..989833e7fc 100644 --- a/pkg/specgen/generate/config_linux_nocgo.go +++ b/pkg/specgen/generate/config_linux_nocgo.go @@ -1,5 +1,5 @@ -//go:build linux && !cgo -// +build linux,!cgo +//go:build linux && !cgo && !remote +// +build linux,!cgo,!remote package generate diff --git a/pkg/specgen/generate/container.go b/pkg/specgen/generate/container.go index 32d9892c15..4469b484be 100644 --- a/pkg/specgen/generate/container.go +++ b/pkg/specgen/generate/container.go @@ -1,3 +1,5 @@ +//go:build !remote + package generate import ( diff --git a/pkg/specgen/generate/container_create.go b/pkg/specgen/generate/container_create.go index c9049674c3..7d5edc9ab1 100644 --- a/pkg/specgen/generate/container_create.go +++ b/pkg/specgen/generate/container_create.go @@ -1,3 +1,5 @@ +//go:build !remote + package generate import ( diff --git a/pkg/specgen/generate/kube/kube.go b/pkg/specgen/generate/kube/kube.go index b3098aa099..180238f82c 100644 --- a/pkg/specgen/generate/kube/kube.go +++ b/pkg/specgen/generate/kube/kube.go @@ -1,3 +1,5 @@ +//go:build !remote + package kube import ( diff --git a/pkg/specgen/generate/namespaces.go b/pkg/specgen/generate/namespaces.go index fa4b6a2f5d..95ac4fb173 100644 --- a/pkg/specgen/generate/namespaces.go +++ b/pkg/specgen/generate/namespaces.go @@ -1,3 +1,5 @@ +//go:build !remote + package generate import ( diff --git a/pkg/specgen/generate/oci.go b/pkg/specgen/generate/oci.go index 3ac1a9b3fe..dd76eac539 100644 --- a/pkg/specgen/generate/oci.go +++ b/pkg/specgen/generate/oci.go @@ -1,3 +1,5 @@ +//go:build !remote + package generate import ( diff --git a/pkg/specgen/generate/oci_freebsd.go b/pkg/specgen/generate/oci_freebsd.go index 56245b5796..ea612af7c7 100644 --- a/pkg/specgen/generate/oci_freebsd.go +++ b/pkg/specgen/generate/oci_freebsd.go @@ -1,4 +1,4 @@ -//go:build freebsd +//go:build freebsd && !remote package generate diff --git a/pkg/specgen/generate/oci_linux.go b/pkg/specgen/generate/oci_linux.go index b3cede76dd..9dc226cc0b 100644 --- a/pkg/specgen/generate/oci_linux.go +++ b/pkg/specgen/generate/oci_linux.go @@ -1,3 +1,5 @@ +//go:build !remote + package generate import ( diff --git a/pkg/specgen/generate/oci_unsupported.go b/pkg/specgen/generate/oci_unsupported.go index 7e1b8c42ca..4943a09beb 100644 --- a/pkg/specgen/generate/oci_unsupported.go +++ b/pkg/specgen/generate/oci_unsupported.go @@ -1,5 +1,5 @@ -//go:build !linux && !freebsd -// +build !linux,!freebsd +//go:build !linux && !freebsd && !remote +// +build !linux,!freebsd,!remote package generate diff --git a/pkg/specgen/generate/ports.go b/pkg/specgen/generate/ports.go index 782a7f65ac..1d0d9c2059 100644 --- a/pkg/specgen/generate/ports.go +++ b/pkg/specgen/generate/ports.go @@ -1,3 +1,5 @@ +//go:build !remote + package generate import ( diff --git a/pkg/specgen/generate/security_freebsd.go b/pkg/specgen/generate/security_freebsd.go index 5fd66c7695..3c858ed5ad 100644 --- a/pkg/specgen/generate/security_freebsd.go +++ b/pkg/specgen/generate/security_freebsd.go @@ -1,3 +1,5 @@ +//go:build !remote + package generate import ( diff --git a/pkg/specgen/generate/security_linux.go b/pkg/specgen/generate/security_linux.go index 11870c8d95..ada68d9d4f 100644 --- a/pkg/specgen/generate/security_linux.go +++ b/pkg/specgen/generate/security_linux.go @@ -1,3 +1,5 @@ +//go:build !remote + package generate import ( diff --git a/pkg/specgen/generate/security_unsupported.go b/pkg/specgen/generate/security_unsupported.go index d0f937e444..e10cdb405b 100644 --- a/pkg/specgen/generate/security_unsupported.go +++ b/pkg/specgen/generate/security_unsupported.go @@ -1,5 +1,5 @@ -//go:build !linux && !freebsd -// +build !linux,!freebsd +//go:build !linux && !freebsd && !remote +// +build !linux,!freebsd,!remote package generate diff --git a/pkg/specgen/generate/storage.go b/pkg/specgen/generate/storage.go index ffaaa0e1fb..0dc7eaccde 100644 --- a/pkg/specgen/generate/storage.go +++ b/pkg/specgen/generate/storage.go @@ -1,3 +1,5 @@ +//go:build !remote + package generate import ( diff --git a/pkg/specgen/specgen.go b/pkg/specgen/specgen.go index 2e7078115e..abbc9a9040 100644 --- a/pkg/specgen/specgen.go +++ b/pkg/specgen/specgen.go @@ -6,7 +6,6 @@ import ( "strings" "syscall" - "github.com/containers/common/libimage" nettypes "github.com/containers/common/libnetwork/types" "github.com/containers/image/v5/manifest" "github.com/containers/podman/v4/libpod/define" @@ -558,20 +557,7 @@ type SpecGenerator struct { ContainerResourceConfig ContainerHealthCheckConfig - image *libimage.Image `json:"-"` - resolvedImageName string `json:"-"` -} - -// SetImage sets the associated for the generator. -func (s *SpecGenerator) SetImage(image *libimage.Image, resolvedImageName string) { - s.image = image - s.resolvedImageName = resolvedImageName -} - -// Image returns the associated image for the generator. -// May be nil if no image has been set yet. -func (s *SpecGenerator) GetImage() (*libimage.Image, string) { - return s.image, s.resolvedImageName + cacheLibImage } type Secret struct { diff --git a/pkg/specgen/specgen_local.go b/pkg/specgen/specgen_local.go new file mode 100644 index 0000000000..3ed3ec0435 --- /dev/null +++ b/pkg/specgen/specgen_local.go @@ -0,0 +1,22 @@ +//go:build !remote + +package specgen + +import "github.com/containers/common/libimage" + +type cacheLibImage struct { + image *libimage.Image `json:"-"` + resolvedImageName string `json:"-"` +} + +// SetImage sets the associated for the generator. +func (s *SpecGenerator) SetImage(image *libimage.Image, resolvedImageName string) { + s.image = image + s.resolvedImageName = resolvedImageName +} + +// Image returns the associated image for the generator. +// May be nil if no image has been set yet. +func (s *SpecGenerator) GetImage() (*libimage.Image, string) { + return s.image, s.resolvedImageName +} diff --git a/pkg/specgen/specgen_remote.go b/pkg/specgen/specgen_remote.go new file mode 100644 index 0000000000..7bb83da292 --- /dev/null +++ b/pkg/specgen/specgen_remote.go @@ -0,0 +1,9 @@ +//go:build remote + +package specgen + +// Empty stub we do not use any libimage on the remote client, +// this drastically decreases binary size for the remote client. +// +//nolint:unused // this is needed for the local client +type cacheLibImage struct{}