Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e60c16b

Browse files
author
vinay-lanka
committed
Added tests for lib install with flags
1 parent 4f6e915 commit e60c16b

File tree

7 files changed

+158
-164
lines changed

7 files changed

+158
-164
lines changed

‎arduino/libraries/librariesmanager/install.go‎

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,10 @@ func (lm *LibrariesManager) InstallZipLib(libPath string) error {
9898
if libsDir == nil {
9999
return fmt.Errorf("User directory not set")
100100
}
101-
err := Unzip(libPath, libsDir.String())
102-
if err != nil {
103-
return err
104-
}
105-
return nil
106-
}
107-
108-
//Unzip takes the ZipLibPath and Extracts it to LibsDir
109-
func Unzip(src string, dest string) error {
110101

111102
var filenames []string
112103

113-
r, err := zip.OpenReader(src)
104+
r, err := zip.OpenReader(libPath)
114105
if err != nil {
115106
return err
116107
}
@@ -119,10 +110,10 @@ func Unzip(src string, dest string) error {
119110
for _, f := range r.File {
120111

121112
// Store filename/path for returning and using later on
122-
fpath := filepath.Join(dest, f.Name)
113+
fpath := filepath.Join(libsDir.String(), f.Name)
123114

124-
// Check for ZipSlip. More Info: http://bit.ly/2MsjAWE
125-
if !strings.HasPrefix(fpath, filepath.Clean(dest)+string(os.PathSeparator)) {
115+
// Check for ZipSlip.
116+
if !strings.HasPrefix(fpath, filepath.Clean(libsDir.String())+string(os.PathSeparator)) {
126117
return fmt.Errorf("%s: illegal file path", fpath)
127118
}
128119

@@ -163,24 +154,18 @@ func Unzip(src string, dest string) error {
163154
}
164155

165156
//InstallGitLib installs a library hosted on a git repository on the specified path.
166-
func (lm *LibrariesManager) InstallGitLib(Namestring, gitURL string) error {
157+
func (lm *LibrariesManager) InstallGitLib(url string) error {
167158
libsDir := lm.getUserLibrariesDir()
168159
if libsDir == nil {
169160
return fmt.Errorf("User directory not set")
170161
}
171-
err := Fetch(Name, gitURL, libsDir.String())
172-
if err != nil {
173-
return err
174-
}
175-
return nil
176-
}
162+
i := strings.LastIndex(url, "/")
163+
folder := strings.TrimRight(url[i+1:], ".git")
164+
path := libsDir.String() + "/" + folder
177165

178-
//Fetch Clones the repository to LibsDir
179-
func Fetch(name string, url string, dest string) error {
180-
directory := dest + "/" + name
181-
_, err := git.PlainClone(directory, false, &git.CloneOptions{
182-
URL: url,
183-
RecurseSubmodules: git.DefaultSubmoduleRecursionDepth,
166+
_, err := git.PlainClone(path, false, &git.CloneOptions{
167+
URL: url,
168+
Progress: os.Stdout,
184169
})
185170
if err != nil {
186171
return err

‎cli/lib/install.go‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func initInstallCommand() *cobra.Command {
3636
Example: "" +
3737
" " + os.Args[0] + " lib install AudioZero # for the latest version.\n" +
3838
" " + os.Args[0] + " lib install AudioZero@1.0.0 # for the specific version.",
39-
Args: cobra.MinimumNArgs(1),
39+
Args: cobra.MinimumNArgs(0),
4040
Run: runInstallCommand,
4141
}
4242
installCommand.Flags().BoolVar(&installFlags.noDeps, "no-deps", false, "Do not install dependencies.")
@@ -54,27 +54,30 @@ var installFlags struct {
5454
func runInstallCommand(cmd *cobra.Command, args []string) {
5555
instance := instance.CreateInstanceIgnorePlatformIndexErrors()
5656
if installFlags.zipPath != "" {
57-
ZiplibraryInstallReq := &rpc.ZipLibraryInstallReq{
57+
ziplibraryInstallReq := &rpc.ZipLibraryInstallReq{
5858
Instance: instance,
5959
Path: installFlags.zipPath,
6060
}
61-
_, err := lib.ZipLibraryInstall(context.Background(), ZiplibraryInstallReq)
61+
_, err := lib.ZipLibraryInstall(context.Background(), ziplibraryInstallReq)
6262
if err != nil {
6363
feedback.Errorf("Error installing Zip Library %v", err)
6464
os.Exit(errorcodes.ErrGeneric)
6565
}
6666
} else if installFlags.gitURL != "" {
67-
GitlibraryInstallReq := &rpc.GitLibraryInstallReq{
67+
gitlibraryInstallReq := &rpc.GitLibraryInstallReq{
6868
Instance: instance,
69-
Name: args[0],
7069
Url: installFlags.gitURL,
7170
}
72-
_, err := lib.GitLibraryInstall(context.Background(), GitlibraryInstallReq)
71+
_, err := lib.GitLibraryInstall(context.Background(), gitlibraryInstallReq)
7372
if err != nil {
7473
feedback.Errorf("Error installing Git Library %v", err)
7574
os.Exit(errorcodes.ErrGeneric)
7675
}
7776
} else {
77+
if len(args) == 0 {
78+
cmd.Help()
79+
os.Exit(errorcodes.ErrGeneric)
80+
}
7881
libRefs, err := ParseLibraryReferenceArgsAndAdjustCase(instance, args)
7982
if err != nil {
8083
feedback.Errorf("Arguments error: %v", err)

‎commands/lib/install.go‎

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,39 +80,24 @@ func installLibrary(lm *librariesmanager.LibrariesManager, libRelease *libraries
8080
func ZipLibraryInstall(ctx context.Context, req *rpc.ZipLibraryInstallReq) (*rpc.ZipLibraryInstallResp, error) {
8181
res := &rpc.ZipLibraryInstallResp{}
8282
lm := commands.GetLibraryManager(req.GetInstance().GetId())
83-
Path := req.GetPath()
84-
if err := installZipLibrary(lm, Path); err != nil {
83+
libPath := req.GetPath()
84+
if err := lm.InstallZipLib(libPath); err != nil {
8585
res.Status = "Error installing Zip Library"
8686
return res, err
8787
}
8888
res.Status = "Success! Installed Zip Library"
8989
return res, nil
9090
}
9191

92-
func installZipLibrary(lm *librariesmanager.LibrariesManager, libPath string) error {
93-
if err := lm.InstallZipLib(libPath); err != nil {
94-
return err
95-
}
96-
return nil
97-
}
98-
9992
//GitLibraryInstall FIXMEDOC
10093
func GitLibraryInstall(ctx context.Context, req *rpc.GitLibraryInstallReq) (*rpc.GitLibraryInstallResp, error) {
10194
res := &rpc.GitLibraryInstallResp{}
10295
lm := commands.GetLibraryManager(req.GetInstance().GetId())
103-
URL := req.GetUrl()
104-
Name := req.GetName()
105-
if err := installGitLibrary(lm, Name, URL); err != nil {
96+
url := req.GetUrl()
97+
if err := lm.InstallGitLib(url); err != nil {
10698
res.Status = "Error installing Git Library"
10799
return res, err
108100
}
109101
res.Status = "Success! Installed Git Library"
110102
return res, nil
111103
}
112-
113-
func installGitLibrary(lm *librariesmanager.LibrariesManager, Name string, gitURL string) error {
114-
if err := lm.InstallGitLib(Name, gitURL); err != nil {
115-
return err
116-
}
117-
return nil
118-
}

‎go.mod‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ require (
2020
github.com/h2non/filetype v1.0.8 // indirect
2121
github.com/imjasonmiller/godice v0.1.2
2222
github.com/juju/loggo v0.0.0-20190526231331-6e530bcce5d8 // indirect
23-
github.com/leonelquinteros/gotext v1.4.0
24-
github.com/marcinbor85/gohex v0.0.0-20200531163658-baab2527a9a2
25-
github.com/juju/testing v0.0.0-20190429233213-dfc56b8c09fc // indirect
2623
github.com/kr/pretty v0.2.0 // indirect
2724
github.com/kr/text v0.2.0 // indirect
25+
github.com/leonelquinteros/gotext v1.4.0
26+
github.com/marcinbor85/gohex v0.0.0-20200531163658-baab2527a9a2
2827
github.com/mattn/go-colorable v0.1.2
2928
github.com/mattn/go-isatty v0.0.8
3029
github.com/mattn/go-runewidth v0.0.9 // indirect
@@ -47,17 +46,13 @@ require (
4746
go.bug.st/relaxed-semver v0.0.0-20190922224835-391e10178d18
4847
go.bug.st/serial v1.1.1
4948
go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45 // indirect
50-
golang.org/x/crypto v0.0.0-20200406173513-056763e48d71// indirect
49+
golang.org/x/crypto v0.0.0-20200406173513-056763e48d71
5150
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e
52-
golang.org/x/sys v0.0.0-20200408040146-ea54a3c99b9b // indirect
5351
golang.org/x/text v0.3.2
5452
google.golang.org/grpc v1.27.0
5553
google.golang.org/protobuf v1.25.0
56-
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce // indirect
57-
gopkg.in/src-d/go-git.v4 v4.13.1
58-
gopkg.in/yaml.v2 v2.3.0
5954
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
6055
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce // indirect
6156
gopkg.in/src-d/go-git.v4 v4.13.1
62-
gopkg.in/yaml.v2 v2.2.4
57+
gopkg.in/yaml.v2 v2.3.0
6358
)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /