Remove symlink before creating new ones

This commit is contained in:
Matthias Loibl 2019-08-12 18:16:31 +02:00
parent d3bb1f4ea4
commit e1580b7968
No known key found for this signature in database
GPG key ID: 78A796CA74CA38BA

View file

@ -21,6 +21,7 @@ import (
"path/filepath"
"github.com/jsonnet-bundler/jsonnet-bundler/spec"
"github.com/pkg/errors"
)
type LocalPackage struct {
@ -39,7 +40,14 @@ func (p *LocalPackage) Install(ctx context.Context, name, dir, version string) (
return "", fmt.Errorf("failed to get current working directory: %v", err)
}
err = os.Symlink(filepath.Join(wd, p.Source.Directory), filepath.Join(wd, dir, name))
destPath := filepath.Join(dir, name)
err = os.RemoveAll(destPath)
if err != nil {
return "", errors.Wrap(err, "failed to clean previous destination path")
}
err = os.Symlink(filepath.Join(wd, p.Source.Directory), filepath.Join(wd, destPath))
if err != nil {
return "", fmt.Errorf("failed to create symlink for local dependency: %v", err)
}