diff --git a/pkg/kubectl/cmd/cp.go b/pkg/kubectl/cmd/cp.go index a5d67de3f96..150fe8ead3f 100644 --- a/pkg/kubectl/cmd/cp.go +++ b/pkg/kubectl/cmd/cp.go @@ -378,11 +378,8 @@ func untarAll(reader io.Reader, destFile, prefix string) error { } func getPrefix(file string) string { - if file[0] == '/' { - // tar strips the leading '/' if it's there, so we will too - return file[1:] - } - return file + // tar strips the leading '/' if it's there, so we will too + return strings.TrimLeft(file, "/") } func execute(f cmdutil.Factory, cmd *cobra.Command, options *ExecOptions) error {