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
be929daa
Commit
be929daa
authored
Jun 24, 2019
by
M00nF1sh
Committed by
Tim Allclair
Aug 01, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactors to kubernetes CP command
parent
f9a243ca
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
24 deletions
+17
-24
cp.go
pkg/kubectl/cmd/cp/cp.go
+1
-4
cp_test.go
pkg/kubectl/cmd/cp/cp_test.go
+16
-20
No files found.
pkg/kubectl/cmd/cp/cp.go
View file @
be929daa
...
...
@@ -500,16 +500,13 @@ func linkJoin(base, link string) string {
if
filepath
.
IsAbs
(
link
)
{
return
link
}
return
filepath
.
Join
(
base
,
link
)
return
filepath
.
Join
(
filepath
.
Dir
(
base
)
,
link
)
}
// isDestRelative returns true if dest is pointing outside the base directory,
// false otherwise.
func
isDestRelative
(
base
,
dest
string
)
bool
{
fullPath
:=
dest
if
!
filepath
.
IsAbs
(
dest
)
{
fullPath
=
filepath
.
Join
(
base
,
dest
)
}
relative
,
err
:=
filepath
.
Rel
(
base
,
fullPath
)
if
err
!=
nil
{
return
false
...
...
pkg/kubectl/cmd/cp/cp_test.go
View file @
be929daa
...
...
@@ -200,12 +200,12 @@ func TestIsDestRelative(t *testing.T) {
}{
{
base
:
"/dir"
,
dest
:
"../link"
,
dest
:
"
/dir/
../link"
,
relative
:
false
,
},
{
base
:
"/dir"
,
dest
:
"../../link"
,
dest
:
"
/dir/
../../link"
,
relative
:
false
,
},
{
...
...
@@ -215,32 +215,27 @@ func TestIsDestRelative(t *testing.T) {
},
{
base
:
"/dir"
,
dest
:
"link"
,
dest
:
"
/dir/
link"
,
relative
:
true
,
},
{
base
:
"/dir"
,
dest
:
"
int/file
/link"
,
dest
:
"
/dir/int/..
/link"
,
relative
:
true
,
},
{
base
:
"
/
dir"
,
dest
:
"
int/..
/link"
,
base
:
"dir"
,
dest
:
"
dir
/link"
,
relative
:
true
,
},
{
base
:
"
/
dir"
,
dest
:
"
/dir
/link"
,
base
:
"dir"
,
dest
:
"
dir/int/..
/link"
,
relative
:
true
,
},
{
base
:
"/dir"
,
dest
:
"/dir/int/../link"
,
relative
:
true
,
},
{
base
:
"/dir"
,
dest
:
"/dir/../../link"
,
base
:
"dir"
,
dest
:
"dir/../../link"
,
relative
:
false
,
},
}
...
...
@@ -792,9 +787,10 @@ func TestUntar(t *testing.T) {
}
return
expected
+
suffix
}
mkBacktickExpectation
:=
func
(
expected
,
suffix
string
)
string
{
dir
,
_
:=
filepath
.
Split
(
filepath
.
Clean
(
expected
))
if
len
(
strings
.
Split
(
dir
,
string
(
os
.
PathSeparator
)))
<=
1
{
mkBacktickExpectation
:=
func
(
path
,
expected
,
suffix
string
)
string
{
linkTarget
:=
filepath
.
Join
(
backtick
(
path
),
"link-target"
)
baseDir
:=
filepath
.
Join
(
testdir
,
dest
)
if
!
isDestRelative
(
baseDir
,
linkJoin
(
filepath
.
Join
(
baseDir
,
path
),
linkTarget
))
{
return
""
}
return
expected
+
suffix
...
...
@@ -812,7 +808,7 @@ func TestUntar(t *testing.T) {
},
file
{
path
:
f
.
path
+
"-outerlink"
,
linkTarget
:
filepath
.
Join
(
backtick
(
f
.
path
),
"link-target"
),
expected
:
mkBacktickExpectation
(
f
.
expected
,
"-outerlink"
),
expected
:
mkBacktickExpectation
(
f
.
path
,
f
.
expected
,
"-outerlink"
),
},
file
{
path
:
f
.
path
+
"-outerlink-abs"
,
linkTarget
:
filepath
.
Join
(
testdir
,
"link-target"
),
...
...
@@ -918,7 +914,7 @@ func TestUntar(t *testing.T) {
// backtick returns a path to one directory up from the target
func
backtick
(
target
string
)
string
{
rel
,
_
:=
filepath
.
Rel
(
filepath
.
Dir
(
target
),
"../"
)
rel
:=
filepath
.
Join
(
filepath
.
Dir
(
target
),
"../"
)
return
rel
}
...
...
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