Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions mgrctl/cmd/cp/cp.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
// SPDX-FileCopyrightText: 2024 SUSE LLC
// SPDX-FileCopyrightText: 2026 YatesMold
//
// SPDX-License-Identifier: Apache-2.0

package cp

import (
"fmt"
"strings"

"github.com/spf13/cobra"
"github.com/uyuni-project/uyuni-tools/shared"
"github.com/uyuni-project/uyuni-tools/shared/kubernetes"
Expand All @@ -25,11 +29,12 @@ func NewCommand(globalFlags *types.GlobalFlags) *cobra.Command {
flags := &flagpole{}

cpCmd := &cobra.Command{
Use: "cp [path/to/source.file] [path/to/destination.file]",
Use: "cp [path/to/source1.file ...] [path/to/destination]",
Short: L("Copy files to and from the containers"),
Long: L(`Takes a source and destination parameters.
One of them can be prefixed with 'server:' to indicate the path is within the server pod.`),
Args: cobra.ExactArgs(2),
Long: L(`Takes at least one source and destination parameters.
Several source files can be passed, the last parameter will be the destination.
Either the source parameters or the destination can be prefixed with 'server:' to indicate the path is within the server pod.`),
Args: cobra.MinimumNArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
viper, err := utils.ReadConfig(cmd, utils.GlobalConfigFilename, globalFlags.ConfigPath)
if err != nil {
Expand All @@ -51,5 +56,21 @@ func NewCommand(globalFlags *types.GlobalFlags) *cobra.Command {

func run(flags *flagpole, _ *cobra.Command, args []string) error {
cnx := shared.NewConnection(flags.Backend, podman.ServerContainerName, kubernetes.ServerFilter)
return cnx.Copy(args[0], args[1], flags.User, flags.Group)
dst := args[len(args)-1]
srcs := args[:len(args)-1]

// Validate that source paths don't mix local and server paths.
hasServerSrc := strings.HasPrefix(srcs[0], "server:")
for _, src := range srcs[1:] {
if strings.HasPrefix(src, "server:") != hasServerSrc {
return fmt.Errorf(L("cannot mix local and server sources"))
}
}

for _, src := range srcs {
if err := cnx.Copy(src, dst, flags.User, flags.Group); err != nil {
return err
}
}
return nil
}
1 change: 1 addition & 0 deletions uyuni-tools.changes.yatesmold.multi-source-cp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Support multiple source files in mgrctl cp (gh#657)