Skip to content

Commit 3eeb725

Browse files
committed
add tools APIlevel compatibility and require pack to be specified
1 parent bb0827a commit 3eeb725

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

main.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,18 @@ var (
3636
gcType = flag.String("gc", "std", "Type of garbage collection. std = Normal garbage collection allowing system to decide (this has been known to cause a stop the world in the middle of a CNC job which can cause lost responses from the CNC controller and thus stalled jobs. use max instead to solve.), off = let memory grow unbounded (you have to send in the gc command manually to garbage collect or you will run out of RAM eventually), max = Force garbage collection on each recv or send on a serial port (this minimizes stop the world events and thus lost serial responses, but increases CPU usage)")
3737
logDump = flag.String("log", "off", "off = (default)")
3838
// hostname. allow user to override, otherwise we look it up
39-
hostname = flag.String("hostname", "unknown-hostname", "Override the hostname we get from the OS")
40-
updateUrl = flag.String("updateUrl", "", "")
41-
appName = flag.String("appName", "", "")
42-
genCert = flag.Bool("generateCert", false, "")
43-
port string
44-
portSSL string
45-
origins = flag.String("origins", "", "Allowed origin list for CORS")
46-
address = flag.String("address", "127.0.0.1", "The address where to listen. Defaults to localhost")
47-
signatureKey = flag.String("signatureKey", "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvc0yZr1yUSen7qmE3cxF\nIE12rCksDnqR+Hp7o0nGi9123eCSFcJ7CkIRC8F+8JMhgI3zNqn4cUEn47I3RKD1\nZChPUCMiJCvbLbloxfdJrUi7gcSgUXrlKQStOKF5Iz7xv1M4XOP3JtjXLGo3EnJ1\npFgdWTOyoSrA8/w1rck4c/ISXZSinVAggPxmLwVEAAln6Itj6giIZHKvA2fL2o8z\nCeK057Lu8X6u2CG8tRWSQzVoKIQw/PKK6CNXCAy8vo4EkXudRutnEYHEJlPkVgPn\n2qP06GI+I+9zKE37iqj0k1/wFaCVXHXIvn06YrmjQw6I0dDj/60Wvi500FuRVpn9\ntwIDAQAB\n-----END PUBLIC KEY-----", "Pem-encoded public key to verify signed commandlines")
48-
Tools tools.Tools
49-
indexURL = flag.String("indexURL", "https://downloads.arduino.cc/packages/package_staging_index.json", "The address from where to download the index json containing the location of upload tools")
39+
hostname = flag.String("hostname", "unknown-hostname", "Override the hostname we get from the OS")
40+
updateUrl = flag.String("updateUrl", "", "")
41+
appName = flag.String("appName", "", "")
42+
genCert = flag.Bool("generateCert", false, "")
43+
port string
44+
portSSL string
45+
origins = flag.String("origins", "", "Allowed origin list for CORS")
46+
address = flag.String("address", "127.0.0.1", "The address where to listen. Defaults to localhost")
47+
signatureKey = flag.String("signatureKey", "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvc0yZr1yUSen7qmE3cxF\nIE12rCksDnqR+Hp7o0nGi9123eCSFcJ7CkIRC8F+8JMhgI3zNqn4cUEn47I3RKD1\nZChPUCMiJCvbLbloxfdJrUi7gcSgUXrlKQStOKF5Iz7xv1M4XOP3JtjXLGo3EnJ1\npFgdWTOyoSrA8/w1rck4c/ISXZSinVAggPxmLwVEAAln6Itj6giIZHKvA2fL2o8z\nCeK057Lu8X6u2CG8tRWSQzVoKIQw/PKK6CNXCAy8vo4EkXudRutnEYHEJlPkVgPn\n2qP06GI+I+9zKE37iqj0k1/wFaCVXHXIvn06YrmjQw6I0dDj/60Wvi500FuRVpn9\ntwIDAQAB\n-----END PUBLIC KEY-----", "Pem-encoded public key to verify signed commandlines")
48+
Tools tools.Tools
49+
indexURL = flag.String("indexURL", "https://downloads.arduino.cc/packages/package_staging_index.json", "The address from where to download the index json containing the location of upload tools")
50+
requiredToolsAPILevel = "v1"
5051
)
5152

5253
type NullWriter int
@@ -97,7 +98,7 @@ func main() {
9798
IndexURL: *indexURL,
9899
Logger: log.New(),
99100
}
100-
Tools.Init()
101+
Tools.Init(requiredToolsAPILevel)
101102

102103
if embedded_autoextract {
103104
// save the config.ini (if it exists)

tools/download.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func (t *Tools) Download(pack, name, version, behaviour string) error {
212212
// Decompress
213213
t.Logger.Println("Unpacking tool " + name)
214214

215-
location := path.Join(dir(), correctTool.Name, correctTool.Version)
215+
location := path.Join(dir(), pack, correctTool.Name, correctTool.Version)
216216
err = os.RemoveAll(location)
217217

218218
if err != nil {

tools/tools.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,19 @@ type Tools struct {
3838
}
3939

4040
// Init creates the Installed map and populates it from a file in .arduino-create
41-
func (t *Tools) Init() {
41+
func (t *Tools) Init(APIlevel string) {
4242
createDir(t.Directory)
4343
t.installed = make(map[string]string)
4444
t.readMap()
45+
if t.installed["apilevel"] != APIlevel {
46+
// wipe the folder and reinitialize the data
47+
os.RemoveAll(t.Directory)
48+
createDir(t.Directory)
49+
t.installed = make(map[string]string)
50+
t.installed["apilevel"] = APIlevel
51+
t.writeMap()
52+
t.readMap()
53+
}
4554
t.Logger.Println(t.installed)
4655
}
4756

0 commit comments

Comments
 (0)