Skip to content

Commit 0506220

Browse files
committed
Fix random tool extraction fail
when ulimit is quite low (for example, when launching as OSX service) extracting a lot of files in a short timespan breaks this limit and aborts any open() after the event. Solved by explicitely closing the handle as soon as possible. Solves bcmi-labs/webide#2225
1 parent 018c3d9 commit 0506220

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

tools/download.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,10 @@ func (t *Tools) Download(pack, name, version, behaviour string) error {
194194
if behaviour == "keep" {
195195
location, ok := t.installed[key]
196196
if ok && pathExists(location) {
197+
// overwrite the default tool with this one
198+
t.installed[correctTool.Name] = location
197199
t.Logger.Println("The tool is already present on the system")
198-
return nil
200+
return t.writeMap()
199201
}
200202
}
201203

@@ -249,6 +251,7 @@ func (t *Tools) Download(pack, name, version, behaviour string) error {
249251
}
250252

251253
if err != nil {
254+
t.Logger.Println("Error extracting the archive: ", err.Error())
252255
return err
253256
}
254257

@@ -430,13 +433,14 @@ func extractTarGz(body []byte, location string) (string, error) {
430433
}
431434

432435
file, err := os.OpenFile(path, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, info.Mode())
433-
if err == nil {
434-
defer file.Close()
436+
if err != nil {
437+
return location, err
435438
}
436439
_, err = io.Copy(file, tarReader)
437440
if err != nil {
438441
//return location, err
439442
}
443+
file.Close()
440444
}
441445
return location, nil
442446
}
@@ -494,6 +498,7 @@ func extractBz2(body []byte, location string) (string, error) {
494498
if err == io.EOF {
495499
break
496500
} else if err != nil {
501+
continue
497502
//return location, err
498503
}
499504

@@ -513,13 +518,14 @@ func extractBz2(body []byte, location string) (string, error) {
513518
}
514519

515520
file, err := os.OpenFile(path, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, info.Mode())
516-
if err == nil {
517-
defer file.Close()
521+
if err != nil {
522+
return location, err
518523
}
519524
_, err = io.Copy(file, tarReader)
520525
if err != nil {
521526
//return location, err
522527
}
528+
file.Close()
523529
}
524530
return location, nil
525531
}

0 commit comments

Comments
 (0)