Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
songlinfeng
container-toolkit
Commits
407f0c2d
Commit
407f0c2d
authored
Oct 22, 2025
by
songlinfeng
Browse files
fix bug linkpath exists
parent
d7e13eb9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
0 deletions
+12
-0
cmd/dtk-cdi-hook/create-symlinks/create-symlinks.go
cmd/dtk-cdi-hook/create-symlinks/create-symlinks.go
+12
-0
No files found.
cmd/dtk-cdi-hook/create-symlinks/create-symlinks.go
View file @
407f0c2d
...
...
@@ -97,6 +97,14 @@ func (m command) run(c *cli.Context, cfg *config) error {
return
nil
}
func
DirExists
(
path
string
)
bool
{
_
,
err
:=
os
.
Stat
(
path
)
if
os
.
IsNotExist
(
err
){
return
false
}
return
err
==
nil
}
func
(
m
command
)
createLink
(
created
map
[
string
]
bool
,
hostRoot
string
,
containerRoot
string
,
target
string
,
link
string
)
error
{
linkPath
,
err
:=
changeRoot
(
hostRoot
,
containerRoot
,
link
)
if
err
!=
nil
{
...
...
@@ -113,6 +121,10 @@ func (m command) createLink(created map[string]bool, hostRoot string, containerR
}
m
.
logger
.
Infof
(
"Symlinking %v to %v"
,
linkPath
,
targetPath
)
if
DirExists
(
linkPath
)
{
os
.
RemoveAll
(
linkPath
)
m
.
logger
.
Infof
(
"remove dir %v"
,
linkPath
)
}
err
=
os
.
MkdirAll
(
filepath
.
Dir
(
linkPath
),
0755
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to create directory: %v"
,
err
)
...
...
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