diff --git a/main.go b/main.go index 49add9640..6b0012dfd 100755 --- a/main.go +++ b/main.go @@ -335,7 +335,7 @@ var homeTemplate = template.Must(template.New("home").Parse(homeTemplateHtml)) const homeTemplateHtml = `<!DOCTYPE html> <html> <head> -<title>Serial Port Example</title> +<title>Arduino Create Agent Debug Console</title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.3.5/socket.io.min.js"></script> <script type="text/javascript"> diff --git a/tools/download.go b/tools/download.go index df966ae7c..aa72a8933 100644 --- a/tools/download.go +++ b/tools/download.go @@ -157,10 +157,10 @@ func pathExists(path string) bool { // if it already exists. func (t *Tools) Download(pack, name, version, behaviour string) error { - index_file := path.Join(t.Directory, "package_index.json") - signature_file := path.Join(t.Directory, "package_index.json.sig") + index_file := filepath.Join(t.Directory, "package_index.json") + signature_file := filepath.Join(t.Directory, "package_index.json.sig") - if _, err := os.Stat(path.Join(t.Directory, "package_index.json")); err != nil || time.Since(t.LastRefresh) > 1*time.Hour { + if _, err := os.Stat(filepath.Join(t.Directory, "package_index.json")); err != nil || time.Since(t.LastRefresh) > 1*time.Hour { // Download the file again and save it err = t.DownloadPackageIndex(index_file, signature_file) if err != nil { @@ -225,9 +225,9 @@ func (t *Tools) Download(pack, name, version, behaviour string) error { } // Decompress - t.Logger("Unpacking tool " + name) - location := path.Join("tmp", dir(), pack, correctTool.Name, correctTool.Version) + location := path.Join(dir(), pack, correctTool.Name, correctTool.Version) + t.Logger("Unpacking tool " + name + " in location: " + location) err = os.RemoveAll(location) if err != nil { @@ -377,7 +377,7 @@ func removeStringFromSlice(s []string, r string) []string { func findBaseDir(dirList []string) string { if len(dirList) == 1 { - return filepath.Dir(dirList[0]) + "/" + return fmt.Sprintf("%s%s", filepath.Dir(dirList[0]), string(os.PathSeparator)) } // https://github.com/backdrop-ops/contrib/issues/55#issuecomment-73814500 @@ -388,12 +388,12 @@ func findBaseDir(dirList []string) string { commonBaseDir := commonPrefix(os.PathSeparator, dirList) if commonBaseDir != "" { - commonBaseDir = commonBaseDir + "/" + commonBaseDir = fmt.Sprintf("%s%s", commonBaseDir, string(os.PathSeparator)) } return commonBaseDir } -func extractZip(log func(msg string) , body []byte, location string) (string, error) { +func extractZip(log func(msg string), body []byte, location string) (string, error) { path, err := utilities.SaveFileonTempDir("tooldownloaded.zip", bytes.NewReader(body)) r, err := zip.OpenReader(path) if err != nil { @@ -407,10 +407,16 @@ func extractZip(log func(msg string) , body []byte, location string) (string, e } basedir := findBaseDir(dirList) - log(fmt.Sprintf("selected baseDir %s from Zip Archive Content: %v", basedir, dirList)) + log(fmt.Sprintf("given location: %s > selected baseDir %s from Zip Archive Content: %v",location, basedir, dirList)) for _, f := range r.File { - fullname := filepath.Join(location, strings.Replace(f.Name, basedir, "", -1)) + normLocation := location + normName := filepath.Join(strings.Split(filepath.ToSlash(f.Name), "/")...) + normBaseDir := filepath.Join(strings.Split(filepath.ToSlash(basedir), "/")...)+ string(os.PathSeparator) + fullname := filepath.Join(normLocation, strings.Replace(normName, normBaseDir, "", -1)) + + log(fmt.Sprintf("selected fullname %s from replacing in %s the string %s", fullname, normName, normBaseDir)) + if f.FileInfo().IsDir() { os.MkdirAll(fullname, f.FileInfo().Mode().Perm()) } else { @@ -441,7 +447,7 @@ func extractZip(log func(msg string) , body []byte, location string) (string, e return location, nil } -func extractTarGz(log func(msg string),body []byte, location string) (string, error) { +func extractTarGz(log func(msg string), body []byte, location string) (string, error) { bodyCopy := make([]byte, len(body)) copy(bodyCopy, body) tarFile, _ := gzip.NewReader(bytes.NewReader(body)) @@ -505,8 +511,7 @@ func extractTarGz(log func(msg string),body []byte, location string) (string, er return location, nil } - -func extractBz2(log func(msg string),body []byte, location string) (string, error) { +func extractBz2(log func(msg string), body []byte, location string) (string, error) { bodyCopy := make([]byte, len(body)) copy(bodyCopy, body) tarFile := bzip2.NewReader(bytes.NewReader(body)) @@ -572,7 +577,6 @@ func extractBz2(log func(msg string),body []byte, location string) (string, err return location, nil } - func (t *Tools) installDrivers(location string) error { OK_PRESSED := 6 extension := ".bat" @@ -603,14 +607,14 @@ func (t *Tools) installDrivers(location string) error { } func makeExecutable(location string) error { - location = path.Join(location, "bin") + location = filepath.Join(location, "bin") files, err := ioutil.ReadDir(location) if err != nil { return err } for _, file := range files { - err = os.Chmod(path.Join(location, file.Name()), 0755) + err = os.Chmod(filepath.Join(location, file.Name()), 0755) if err != nil { return err }