Skip to content

Commit 4bc505c

Browse files
committed
Recognize hyphenated directory names in some Rust crates.
1 parent 59abd2a commit 4bc505c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pkg/runtime/ecosystem/rust.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package ecosystem
33
import (
44
"os"
55
"path/filepath"
6+
"strings"
67

78
"github.com/ActiveState/cli/internal/errs"
89
"github.com/ActiveState/cli/internal/fileutils"
@@ -76,7 +77,15 @@ func (e *Rust) Add(artifact *buildplan.Artifact, artifactSrcPath string) ([]stri
7677
if err != nil {
7778
return nil, errs.Wrap(err, "Unable to unpack downloaded crate")
7879
}
79-
err = os.Rename(filepath.Join(unpackDir, artifact.Name()+"-"+artifact.Version()), absVendored)
80+
unpackedDir := filepath.Join(unpackDir, artifact.Name()+"-"+artifact.Version())
81+
if !fileutils.DirExists(unpackedDir) {
82+
// Some crates use hyphens instead of underscores in their packaged directory names.
83+
unpackedDir = filepath.Join(unpackDir, strings.ReplaceAll(artifact.Name(), "_", "-")+"-"+artifact.Version())
84+
}
85+
if !fileutils.DirExists(unpackedDir) {
86+
return nil, errs.New("Downloaded crate (%s) uses an unknown, top-level directory name", artifact.Name())
87+
}
88+
err = os.Rename(unpackedDir, absVendored)
8089
if err != nil {
8190
return nil, errs.Wrap(err, "Unable to rename unpacked crate")
8291
}

0 commit comments

Comments
 (0)