Commit 407f0c2d authored by songlinfeng's avatar songlinfeng
Browse files

fix bug linkpath exists

parent d7e13eb9
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment