Skip to content

Commit 8c6228a

Browse files
committed
Clean up temp if install is interrupted
1 parent eb0f5d5 commit 8c6228a

File tree

9 files changed

+174
-28
lines changed

9 files changed

+174
-28
lines changed

Diff for: Gopkg.lock

+12-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Gopkg.toml

-4
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@
5959
name = "github.com/codeclysm/cc"
6060
version = "1.2.1"
6161

62-
[[constraint]]
63-
name = "github.com/codeclysm/extract"
64-
version = "1.1.1"
65-
6662
[[constraint]]
6763
branch = "master"
6864
name = "github.com/mitchellh/go-homedir"

Diff for: arduino/resources/install.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
package resources
1919

2020
import (
21+
"context"
2122
"fmt"
2223
"os"
2324

2425
paths "github.com/arduino/go-paths-helper"
2526
"github.com/codeclysm/extract"
27+
"go.bug.st/cleanup"
2628
)
2729

2830
// Install installs the resource in three steps:
@@ -54,7 +56,9 @@ func (release *DownloadResource) Install(downloadDir, tempPath, destDir *paths.P
5456
defer file.Close()
5557

5658
// Extract into temp directory
57-
if err := extract.Archive(file, tempDir.String(), nil); err != nil {
59+
ctx, cancel := cleanup.InterruptableContext(context.Background())
60+
defer cancel()
61+
if err := extract.Archive(ctx, file, tempDir.String(), nil); err != nil {
5862
return fmt.Errorf("extracting archive: %s", err)
5963
}
6064

Diff for: vendor/github.com/codeclysm/extract/cancelable_reader.go

+32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: vendor/github.com/codeclysm/extract/extract.go

+48-20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: vendor/go.bug.st/cleanup/LICENSE

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
Copyright (c) 2018, Cristian Maglie.
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions
7+
are met:
8+
9+
1. Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright
13+
notice, this list of conditions and the following disclaimer in
14+
the documentation and/or other materials provided with the
15+
distribution.
16+
17+
3. Neither the name of the copyright holder nor the names of its
18+
contributors may be used to endorse or promote products derived
19+
from this software without specific prior written permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24+
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25+
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31+
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32+
POSSIBILITY OF SUCH DAMAGE.
33+

Diff for: vendor/go.bug.st/cleanup/context.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// Copyright 2018 Cristian Maglie. All rights reserved.
3+
// Use of this source code is governed by a BSD-style
4+
// license that can be found in the LICENSE file.
5+
//
6+
7+
package cleanup
8+
9+
import (
10+
"context"
11+
"os"
12+
"os/signal"
13+
)
14+
15+
// InterruptableContext adds to a context the capability to be interrupted by the os.Interrupt signal.
16+
func InterruptableContext(inCtx context.Context) (context.Context, context.CancelFunc) {
17+
ctx, cancel := context.WithCancel(inCtx)
18+
go func() {
19+
ctrlC := make(chan os.Signal, 1)
20+
signal.Notify(ctrlC, os.Interrupt)
21+
select {
22+
case <-ctx.Done():
23+
break // used to show test coverage
24+
case <-ctrlC:
25+
cancel()
26+
}
27+
signal.Stop(ctrlC)
28+
close(ctrlC)
29+
}()
30+
return ctx, cancel
31+
}

Diff for: vendor/go.bug.st/cleanup/go.mod

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module go.bug.st/cleanup
2+
3+
require (
4+
github.com/davecgh/go-spew v1.1.1 // indirect
5+
github.com/pmezard/go-difflib v1.0.0 // indirect
6+
github.com/stretchr/testify v1.2.2
7+
)

Diff for: vendor/go.bug.st/cleanup/go.sum

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5+
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
6+
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=

0 commit comments

Comments
 (0)