Skip to content

[WE-168] Dependency rework #267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
36 changes: 20 additions & 16 deletions tools/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down