Skip to content

[WE-168] Path bugfix win #270

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

Merged
merged 7 commits into from
Nov 28, 2018
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
229 changes: 104 additions & 125 deletions Gopkg.lock

Large diffs are not rendered by default.

117 changes: 6 additions & 111 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,76 +27,28 @@

[[constraint]]
name = "github.com/Sirupsen/logrus"
version = "1.0.6"
version = "1.2.0"

[[constraint]]
name = "github.com/blang/semver"
version = "3.5.1"

[[constraint]]
branch = "master"
name = "github.com/creack/goselect"

[[constraint]]
branch = "master"
name = "github.com/getlantern/context"

[[constraint]]
branch = "master"
name = "github.com/getlantern/errors"

[[constraint]]
branch = "master"
name = "github.com/getlantern/filepersist"

[[constraint]]
branch = "master"
name = "github.com/getlantern/golog"

[[constraint]]
branch = "master"
name = "github.com/getlantern/hex"

[[constraint]]
branch = "master"
name = "github.com/getlantern/hidden"

[[constraint]]
branch = "master"
name = "github.com/getlantern/ops"

[[constraint]]
name = "github.com/getlantern/stack"
version = "1.5.1"

[[constraint]]
branch = "master"
revision = "89b3d9c45cc69f861868cc7f3159eba2b4cdfb22"
name = "github.com/getlantern/systray"

[[constraint]]
name = "github.com/gin-gonic/gin"
version = "1.2.0"
version = "1.3.0"

[[constraint]]
name = "github.com/go-ini/ini"
version = "1.38.1"

[[constraint]]
branch = "master"
name = "github.com/googollee/go-engine.io"
version = "1.39.0"

[[constraint]]
branch = "master"
name = "github.com/googollee/go-socket.io"

[[constraint]]
name = "github.com/gorilla/websocket"
version = "1.2.0"

[[constraint]]
branch = "filemode"
name = "github.com/inconshreveable/go-update"

[[constraint]]
name = "github.com/itsjamie/gin-cors"
version = "1.0.0"
Expand All @@ -109,37 +61,13 @@
name = "github.com/kr/binarydist"
version = "0.1.0"

[[constraint]]
name = "github.com/kr/fs"
version = "0.1.0"

[[constraint]]
branch = "master"
name = "github.com/manucorporat/sse"

[[constraint]]
name = "github.com/mattn/go-colorable"
version = "0.0.9"

[[constraint]]
name = "github.com/mattn/go-isatty"
version = "0.0.3"

[[constraint]]
name = "github.com/mattn/go-ole"
version = "1.2.1"

[[constraint]]
name = "github.com/mattn/go-shellwords"
version = "1.0.3"

[[constraint]]
name = "github.com/miekg/dns"
version = "1.0.8"

[[constraint]]
branch = "master"
name = "github.com/mitchellh/go-homedir"
version = "1.0.0"

[[constraint]]
branch = "master"
Expand All @@ -149,10 +77,6 @@
name = "github.com/pkg/errors"
version = "0.8.0"

[[constraint]]
name = "github.com/pkg/sftp"
version = "1.8.0"

[[constraint]]
branch = "master"
name = "github.com/sfreiberg/simplessh"
Expand All @@ -161,18 +85,6 @@
branch = "master"
name = "github.com/skratchdot/open-golang"

[[constraint]]
name = "github.com/smartystreets/goconvey"
version = "1.6.3"

[[constraint]]
name = "github.com/stretchr/testify"
version = "1.2.2"

[[constraint]]
branch = "master"
name = "github.com/vharitonsky/iniflags"

[[constraint]]
branch = "master"
name = "github.com/xrash/smetrics"
Expand All @@ -185,27 +97,10 @@
branch = "master"
name = "golang.org/x/crypto"

[[constraint]]
branch = "master"
name = "golang.org/x/net"

[[constraint]]
branch = "master"
name = "golang.org/x/sys"

[[constraint]]
name = "gopkg.in/bluesuncorp/validator.v5"
version = "5.12.0"

[[constraint]]
branch = "v0"
name = "gopkg.in/inconshreveable/go-update.v0"

[[constraint]]
name = "gopkg.in/ini.v1"
version = "1.38.1"

[prune]
non-go = true
go-tests = true
unused-packages = true
unused-packages = true
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
81 changes: 44 additions & 37 deletions tools/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -226,7 +227,7 @@ func (t *Tools) Download(pack, name, version, behaviour string) error {
// Decompress
t.Logger("Unpacking tool " + name)

location := path.Join(dir(), pack, correctTool.Name, correctTool.Version)
location := path.Join( dir(), pack, correctTool.Name, correctTool.Version)
err = os.RemoveAll(location)

if err != nil {
Expand All @@ -240,12 +241,12 @@ func (t *Tools) Download(pack, name, version, behaviour string) error {

switch srcType {
case "application/zip":
location, err = extractZip(body, location)
location, err = extractZip(t.Logger, body, location)
case "application/x-bz2":
case "application/octet-stream":
location, err = extractBz2(body, location)
location, err = extractBz2(t.Logger, body, location)
case "application/x-gzip":
location, err = extractTarGz(body, location)
location, err = extractTarGz(t.Logger, body, location)
default:
return errors.New("Unknown extension for file " + correctSystem.URL)
}
Expand Down Expand Up @@ -376,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 path.Dir(dirList[0]) + "/"
}

// https://github.com/backdrop-ops/contrib/issues/55#issuecomment-73814500
Expand All @@ -385,14 +386,14 @@ func findBaseDir(dirList []string) string {
dirList = removeStringFromSlice(dirList, v)
}

commonBaseDir := commonPrefix(os.PathSeparator, dirList)
commonBaseDir := commonPrefix('/', dirList)
if commonBaseDir != "" {
commonBaseDir = commonBaseDir + "/"
}
return commonBaseDir
}

func extractZip(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 @@ -406,9 +407,11 @@ func extractZip(body []byte, location string) (string, error) {
}

basedir := findBaseDir(dirList)
log(fmt.Sprintf("selected baseDir %s from Zip Archive Content: %v", basedir, dirList))

for _, f := range r.File {
fullname := filepath.Join(location, strings.Replace(f.Name, basedir, "", -1))
log(fmt.Sprintf("generated fullname %s removing %s from %s", fullname, basedir, f.Name))
if f.FileInfo().IsDir() {
os.MkdirAll(fullname, f.FileInfo().Mode().Perm())
} else {
Expand Down Expand Up @@ -439,7 +442,7 @@ func extractZip(body []byte, location string) (string, error) {
return location, nil
}

func extractTarGz(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 All @@ -456,6 +459,7 @@ func extractTarGz(body []byte, location string) (string, error) {
}

basedir := findBaseDir(dirList)
log(fmt.Sprintf("selected baseDir %s from TarGz Archive Content: %v", basedir, dirList))

tarFile, _ = gzip.NewReader(bytes.NewReader(bodyCopy))
tarReader = tar.NewReader(tarFile)
Expand Down Expand Up @@ -502,36 +506,8 @@ func extractTarGz(body []byte, location string) (string, error) {
return location, nil
}

func (t *Tools) installDrivers(location string) error {
OK_PRESSED := 6
extension := ".bat"
preamble := ""
if runtime.GOOS != "windows" {
extension = ".sh"
// add ./ to force locality
preamble = "./"
}
if _, err := os.Stat(filepath.Join(location, "post_install"+extension)); err == nil {
t.Logger("Installing drivers")
ok := MessageBox("Installing drivers", "We are about to install some drivers needed to use Arduino/Genuino boards\nDo you want to continue?")
if ok == OK_PRESSED {
os.Chdir(location)
t.Logger(preamble + "post_install" + extension)
oscmd := exec.Command(preamble + "post_install" + extension)
if runtime.GOOS != "linux" {
// spawning a shell could be the only way to let the user type his password
TellCommandNotToSpawnShell(oscmd)
}
err = oscmd.Run()
return err
} else {
return errors.New("Could not install drivers")
}
}
return nil
}

func extractBz2(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 All @@ -548,6 +524,7 @@ func extractBz2(body []byte, location string) (string, error) {
}

basedir := findBaseDir(dirList)
log(fmt.Sprintf("selected baseDir %s from Bz2 Archive Content: %v", basedir, dirList))

tarFile = bzip2.NewReader(bytes.NewReader(bodyCopy))
tarReader = tar.NewReader(tarFile)
Expand Down Expand Up @@ -596,6 +573,36 @@ func extractBz2(body []byte, location string) (string, error) {
return location, nil
}


func (t *Tools) installDrivers(location string) error {
OK_PRESSED := 6
extension := ".bat"
preamble := ""
if runtime.GOOS != "windows" {
extension = ".sh"
// add ./ to force locality
preamble = "./"
}
if _, err := os.Stat(filepath.Join(location, "post_install"+extension)); err == nil {
t.Logger("Installing drivers")
ok := MessageBox("Installing drivers", "We are about to install some drivers needed to use Arduino/Genuino boards\nDo you want to continue?")
if ok == OK_PRESSED {
os.Chdir(location)
t.Logger(preamble + "post_install" + extension)
oscmd := exec.Command(preamble + "post_install" + extension)
if runtime.GOOS != "linux" {
// spawning a shell could be the only way to let the user type his password
TellCommandNotToSpawnShell(oscmd)
}
err = oscmd.Run()
return err
} else {
return errors.New("Could not install drivers")
}
}
return nil
}

func makeExecutable(location string) error {
location = path.Join(location, "bin")
files, err := ioutil.ReadDir(location)
Expand Down
Loading