Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
1105 Внедрение механизмов обеспечения безопасности цепочки поставки программных проектов
Legacy
scanned-projects
helm
Commits
cf1de4f8
Unverified
Commit
cf1de4f8
authored
5 years ago
by
Matthew Fisher
Browse files
Options
Download
Patches
Plain Diff
fix(sympath): walk symbolic links one once
Signed-off-by:
Matthew Fisher
<
matt.fisher@microsoft.com
>
parent
0c957691
release-2.15
v2.15.2
v2.15.1
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pkg/sympath/walk.go
+2
-1
pkg/sympath/walk.go
pkg/sympath/walk_test.go
+39
-22
pkg/sympath/walk_test.go
with
41 additions
and
23 deletions
+41
-23
pkg/sympath/walk.go
+
2
−
1
View file @
cf1de4f8
...
...
@@ -72,9 +72,10 @@ func symwalk(path string, info os.FileInfo, walkFn filepath.WalkFunc) error {
if
info
,
err
=
os
.
Lstat
(
resolved
);
err
!=
nil
{
return
err
}
if
err
:=
symwalk
(
resolved
,
info
,
walkFn
);
err
!=
nil
&&
err
!=
filepath
.
SkipDir
{
if
err
:=
symwalk
(
path
,
info
,
walkFn
);
err
!=
nil
&&
err
!=
filepath
.
SkipDir
{
return
err
}
return
nil
}
if
err
:=
walkFn
(
path
,
info
,
nil
);
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
pkg/sympath/walk_test.go
+
39
−
22
View file @
cf1de4f8
...
...
@@ -27,36 +27,45 @@ import (
)
type
Node
struct
{
name
string
entries
[]
*
Node
// nil if the entry is a file
mark
int
name
string
entries
[]
*
Node
// nil if the entry is a file
marks
int
expectedMarks
int
symLinkedTo
string
}
var
tree
=
&
Node
{
"testdata"
,
[]
*
Node
{
{
"a"
,
nil
,
0
},
{
"b"
,
[]
*
Node
{},
0
},
{
"c"
,
nil
,
0
},
{
"a"
,
nil
,
0
,
1
,
""
},
{
"b"
,
[]
*
Node
{},
0
,
1
,
""
},
{
"c"
,
nil
,
0
,
2
,
""
},
{
"d"
,
nil
,
0
,
0
,
"c"
},
{
"
d
"
,
"
e
"
,
[]
*
Node
{
{
"x"
,
nil
,
0
},
{
"y"
,
[]
*
Node
{},
0
},
{
"x"
,
nil
,
0
,
1
,
""
},
{
"y"
,
[]
*
Node
{},
0
,
1
,
""
},
{
"z"
,
[]
*
Node
{
{
"u"
,
nil
,
0
},
{
"v"
,
nil
,
0
},
{
"w"
,
nil
,
0
},
{
"u"
,
nil
,
0
,
1
,
""
},
{
"v"
,
nil
,
0
,
1
,
""
},
{
"w"
,
nil
,
0
,
1
,
""
},
},
0
,
1
,
""
,
},
},
0
,
1
,
""
,
},
},
0
,
1
,
""
,
}
func
walkTree
(
n
*
Node
,
path
string
,
f
func
(
path
string
,
n
*
Node
))
{
...
...
@@ -69,24 +78,32 @@ func walkTree(n *Node, path string, f func(path string, n *Node)) {
func
makeTree
(
t
*
testing
.
T
)
{
walkTree
(
tree
,
tree
.
name
,
func
(
path
string
,
n
*
Node
)
{
if
n
.
entries
==
nil
{
fd
,
err
:=
os
.
Create
(
path
)
if
err
!=
nil
{
t
.
Errorf
(
"makeTree: %v"
,
err
)
return
if
n
.
symLinkedTo
!=
""
{
if
err
:=
os
.
Symlink
(
n
.
symLinkedTo
,
path
);
err
!=
nil
{
t
.
Fatalf
(
"makeTree: %v"
,
err
)
}
}
else
{
fd
,
err
:=
os
.
Create
(
path
)
if
err
!=
nil
{
t
.
Fatalf
(
"makeTree: %v"
,
err
)
return
}
fd
.
Close
()
}
fd
.
Close
()
}
else
{
os
.
Mkdir
(
path
,
0770
)
if
err
:=
os
.
Mkdir
(
path
,
0770
);
err
!=
nil
{
t
.
Fatalf
(
"makeTree: %v"
,
err
)
}
}
})
}
func
checkMarks
(
t
*
testing
.
T
,
report
bool
)
{
walkTree
(
tree
,
tree
.
name
,
func
(
path
string
,
n
*
Node
)
{
if
n
.
mark
!=
1
&&
report
{
t
.
Errorf
(
"node %s mark = %d; expected
1
"
,
path
,
n
.
mark
)
if
n
.
mark
s
!=
n
.
expectedMarks
&&
report
{
t
.
Errorf
(
"node %s mark = %d; expected
%d
"
,
path
,
n
.
mark
s
,
n
.
expectedMarks
)
}
n
.
mark
=
0
n
.
mark
s
=
0
})
}
...
...
@@ -104,7 +121,7 @@ func mark(info os.FileInfo, err error, errors *[]error, clear bool) error {
name
:=
info
.
Name
()
walkTree
(
tree
,
tree
.
name
,
func
(
path
string
,
n
*
Node
)
{
if
n
.
name
==
name
{
n
.
mark
++
n
.
mark
s
++
}
})
return
nil
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets