Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
4a433102
Unverified
Commit
4a433102
authored
Oct 10, 2017
by
bruceauyeung
Committed by
Maciej Szulik
Jun 05, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kubectl cp support colons-in-filename
parent
d373eaa4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
25 deletions
+33
-25
cp.go
pkg/kubectl/cmd/cp.go
+27
-24
cp_test.go
pkg/kubectl/cmd/cp_test.go
+6
-1
No files found.
pkg/kubectl/cmd/cp.go
View file @
4a433102
...
...
@@ -113,30 +113,25 @@ var (
)
func
extractFileSpec
(
arg
string
)
(
fileSpec
,
error
)
{
pieces
:=
strings
.
Split
(
arg
,
":"
)
if
len
(
pieces
)
==
1
{
if
i
:=
strings
.
Index
(
arg
,
":"
);
i
==
-
1
{
return
fileSpec
{
File
:
arg
},
nil
}
if
len
(
pieces
)
!=
2
{
// FIXME Kubernetes can't copy files that contain a ':'
// character.
return
fileSpec
{},
errFileSpecDoesntMatchFormat
}
file
:=
pieces
[
1
]
pieces
=
strings
.
Split
(
pieces
[
0
],
"/"
)
if
len
(
pieces
)
==
1
{
return
fileSpec
{
PodName
:
pieces
[
0
],
File
:
file
,
},
nil
}
if
len
(
pieces
)
==
2
{
return
fileSpec
{
PodNamespace
:
pieces
[
0
],
PodName
:
pieces
[
1
],
File
:
file
,
},
nil
}
else
if
i
>
0
{
file
:=
arg
[
i
+
1
:
]
pod
:=
arg
[
:
i
]
pieces
:=
strings
.
Split
(
pod
,
"/"
)
if
len
(
pieces
)
==
1
{
return
fileSpec
{
PodName
:
pieces
[
0
],
File
:
file
,
},
nil
}
if
len
(
pieces
)
==
2
{
return
fileSpec
{
PodNamespace
:
pieces
[
0
],
PodName
:
pieces
[
1
],
File
:
file
,
},
nil
}
}
return
fileSpec
{},
errFileSpecDoesntMatchFormat
...
...
@@ -177,13 +172,21 @@ func (o *CopyOptions) Run(args []string) error {
if
err
!=
nil
{
return
err
}
if
len
(
srcSpec
.
PodName
)
!=
0
&&
len
(
destSpec
.
PodName
)
!=
0
{
if
_
,
err
:=
os
.
Stat
(
args
[
0
]);
err
==
nil
{
return
o
.
copyToPod
(
fileSpec
{
File
:
args
[
0
]},
destSpec
)
}
return
fmt
.
Errorf
(
"src doesn't exist in local filesystem"
)
}
if
len
(
srcSpec
.
PodName
)
!=
0
{
return
o
.
copyFromPod
(
srcSpec
,
destSpec
)
}
if
len
(
destSpec
.
PodName
)
!=
0
{
return
o
.
copyToPod
(
srcSpec
,
destSpec
)
}
return
fmt
.
Errorf
(
"
O
ne of src or dest must be a remote file specification"
)
return
fmt
.
Errorf
(
"
o
ne of src or dest must be a remote file specification"
)
}
// checkDestinationIsDir receives a destination fileSpec and
...
...
pkg/kubectl/cmd/cp_test.go
View file @
4a433102
...
...
@@ -71,13 +71,18 @@ func TestExtractFileSpec(t *testing.T) {
expectedFile
:
"/some/file"
,
},
{
spec
:
"
some:bad:spec
"
,
spec
:
"
:file:not:exist:in:local:filesystem
"
,
expectErr
:
true
,
},
{
spec
:
"namespace/pod/invalid:/some/file"
,
expectErr
:
true
,
},
{
spec
:
"pod:/some/filenamewith:in"
,
expectedPod
:
"pod"
,
expectedFile
:
"/some/filenamewith:in"
,
},
}
for
_
,
test
:=
range
tests
{
spec
,
err
:=
extractFileSpec
(
test
.
spec
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment