Skip to content

Commit a4888f4

Browse files
committed
Add cleanup on Ctl+C
1 parent 33e41b2 commit a4888f4

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

connect.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ import (
77
"io"
88
"net"
99
"os"
10+
"os/signal"
1011
"path"
1112
"strconv"
1213
"strings"
1314
"sync"
15+
"syscall"
1416
"time"
1517

1618
humanize "github.com/dustin/go-humanize"
1719
"github.com/schollz/progressbar"
18-
"github.com/schollz/tarinator-go"
20+
tarinator "github.com/schollz/tarinator-go"
1921

2022
"github.com/pkg/errors"
2123
log "github.com/sirupsen/logrus"
@@ -100,7 +102,27 @@ func NewConnection(flags *Flags) (*Connection, error) {
100102
return c, nil
101103
}
102104

105+
func (c *Connection) cleanup() {
106+
log.Debug("cleaning")
107+
for id := 1; id <= 8; id++ {
108+
os.Remove(path.Join(c.Path, c.File.Name+".enc."+strconv.Itoa(id)))
109+
}
110+
os.Remove(path.Join(c.Path, c.File.Name+".enc"))
111+
112+
}
113+
103114
func (c *Connection) Run() error {
115+
// catch the Ctl+C
116+
catchCtlC := make(chan os.Signal, 2)
117+
signal.Notify(catchCtlC, os.Interrupt, syscall.SIGTERM)
118+
go func() {
119+
<-catchCtlC
120+
c.cleanup()
121+
fmt.Println("\nExiting")
122+
os.Exit(1)
123+
}()
124+
defer c.cleanup()
125+
104126
forceSingleThreaded := false
105127
if c.IsSender {
106128
fsize, err := FileSize(path.Join(c.File.Path, c.File.Name))

0 commit comments

Comments
 (0)