mirror of
https://github.com/podman-container-tools/podman.git
synced 2026-11-02 09:07:33 +00:00
Merge pull request #12827 from edsantiago/image_scp_quiet
podman image scp: implement --quiet
This commit is contained in:
commit
f69fcb2483
2 changed files with 32 additions and 31 deletions
|
|
@ -46,6 +46,7 @@ var (
|
|||
|
||||
var (
|
||||
parentFlags []string
|
||||
quiet bool
|
||||
source entities.ImageScpOptions
|
||||
dest entities.ImageScpOptions
|
||||
sshInfo entities.ImageScpConnections
|
||||
|
|
@ -61,7 +62,7 @@ func init() {
|
|||
|
||||
func scpFlags(cmd *cobra.Command) {
|
||||
flags := cmd.Flags()
|
||||
flags.BoolVarP(&source.Quiet, "quiet", "q", false, "Suppress the output")
|
||||
flags.BoolVarP(&quiet, "quiet", "q", false, "Suppress the output")
|
||||
}
|
||||
|
||||
func scp(cmd *cobra.Command, args []string) (finalErr error) {
|
||||
|
|
@ -139,6 +140,7 @@ func scp(cmd *cobra.Command, args []string) (finalErr error) {
|
|||
}
|
||||
}
|
||||
|
||||
source.Quiet = quiet
|
||||
source.File = f.Name() // after parsing the arguments, set the file for the save/load
|
||||
dest.File = source.File
|
||||
if err = os.Remove(source.File); err != nil { // remove the file and simply use its name so podman creates the file upon save. avoids umask errors
|
||||
|
|
@ -203,15 +205,6 @@ func scp(cmd *cobra.Command, args []string) (finalErr error) {
|
|||
}
|
||||
}
|
||||
|
||||
src, err := json.MarshalIndent(source, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dst, err := json.MarshalIndent(dest, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("SOURCE: %s\nDEST: %s\n", string(src), string(dst))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -745,11 +745,17 @@ func putSignature(manifestBlob []byte, mech signature.SigningMechanism, sigStore
|
|||
// TransferRootless creates new podman processes using exec.Command and sudo, transferring images between the given source and destination users
|
||||
func transferRootless(source entities.ImageScpOptions, dest entities.ImageScpOptions, podman string, parentFlags []string) error {
|
||||
var cmdSave *exec.Cmd
|
||||
saveCommand := parentFlags
|
||||
saveCommand = append(saveCommand, []string{"save", "--output", source.File, source.Image}...)
|
||||
saveCommand, loadCommand := parentFlags, parentFlags
|
||||
saveCommand = append(saveCommand, []string{"save"}...)
|
||||
loadCommand = append(loadCommand, []string{"load"}...)
|
||||
if source.Quiet {
|
||||
saveCommand = append(saveCommand, "-q")
|
||||
loadCommand = append(loadCommand, "-q")
|
||||
}
|
||||
|
||||
loadCommand := parentFlags
|
||||
loadCommand = append(loadCommand, []string{"load", "--input", dest.File}...)
|
||||
saveCommand = append(saveCommand, []string{"--output", source.File, source.Image}...)
|
||||
|
||||
loadCommand = append(loadCommand, []string{"--input", dest.File}...)
|
||||
|
||||
if source.User == "root" {
|
||||
cmdSave = exec.Command("sudo", podman)
|
||||
|
|
@ -757,7 +763,7 @@ func transferRootless(source entities.ImageScpOptions, dest entities.ImageScpOpt
|
|||
cmdSave = exec.Command(podman)
|
||||
}
|
||||
cmdSave = utils.CreateSCPCommand(cmdSave, saveCommand)
|
||||
logrus.Debug("Executing save command")
|
||||
logrus.Debugf("Executing save command: %q", cmdSave)
|
||||
err := cmdSave.Run()
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -770,20 +776,22 @@ func transferRootless(source entities.ImageScpOptions, dest entities.ImageScpOpt
|
|||
cmdLoad = exec.Command(podman)
|
||||
}
|
||||
cmdLoad = utils.CreateSCPCommand(cmdLoad, loadCommand)
|
||||
logrus.Debug("Executing load command")
|
||||
err = cmdLoad.Run()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
logrus.Debugf("Executing load command: %q", cmdLoad)
|
||||
return cmdLoad.Run()
|
||||
}
|
||||
|
||||
// TransferRootless creates new podman processes using exec.Command and su/machinectl, transferring images between the given source and destination users
|
||||
// TransferRootful creates new podman processes using exec.Command and su/machinectl, transferring images between the given source and destination users
|
||||
func transferRootful(source entities.ImageScpOptions, dest entities.ImageScpOptions, podman string, parentFlags []string) error {
|
||||
basicCommand := []string{podman}
|
||||
basicCommand = append(basicCommand, parentFlags...)
|
||||
saveCommand := append(basicCommand, []string{"save", "--output", source.File, source.Image}...)
|
||||
loadCommand := append(basicCommand, []string{"load", "--input", dest.File}...)
|
||||
saveCommand := append(basicCommand, "save")
|
||||
loadCommand := append(basicCommand, "load")
|
||||
if source.Quiet {
|
||||
saveCommand = append(saveCommand, "-q")
|
||||
loadCommand = append(loadCommand, "-q")
|
||||
}
|
||||
saveCommand = append(saveCommand, []string{"--output", source.File, source.Image}...)
|
||||
loadCommand = append(loadCommand, []string{"--input", dest.File}...)
|
||||
save := []string{strings.Join(saveCommand, " ")}
|
||||
load := []string{strings.Join(loadCommand, " ")}
|
||||
|
||||
|
|
@ -846,18 +854,18 @@ func lookupUser(u string) (*user.User, error) {
|
|||
func execSu(execUser *user.User, command []string) error {
|
||||
cmd := exec.Command("su", "-l", execUser.Username, "--command")
|
||||
cmd = utils.CreateSCPCommand(cmd, command)
|
||||
logrus.Debug("Executing command su")
|
||||
logrus.Debugf("Executing via su: %q", cmd)
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
func execMachine(execUser *user.User, command []string, machinectl string) error {
|
||||
var cmd *exec.Cmd
|
||||
verb := machinectl
|
||||
args := []string{"shell", "-q", execUser.Username + "@.host"}
|
||||
if execUser.Uid == "0" {
|
||||
cmd = exec.Command("sudo", machinectl, "shell", "-q", execUser.Username+"@.host")
|
||||
} else {
|
||||
cmd = exec.Command(machinectl, "shell", "-q", execUser.Username+"@.host")
|
||||
args = append([]string{verb}, args...)
|
||||
verb = "sudo"
|
||||
}
|
||||
cmd = utils.CreateSCPCommand(cmd, command)
|
||||
logrus.Debug("Executing command machinectl")
|
||||
cmd := utils.CreateSCPCommand(exec.Command(verb, args...), command)
|
||||
logrus.Debugf("Executing via machinectl: %q", cmd)
|
||||
return cmd.Run()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue