mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
Add cleanup on Ctl+C
This commit is contained in:
parent
407d85270c
commit
e8d5afe1fa
1 changed files with 23 additions and 1 deletions
24
connect.go
24
connect.go
|
@ -7,15 +7,17 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
"os/signal"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/dustin/go-humanize"
|
"github.com/dustin/go-humanize"
|
||||||
"github.com/schollz/progressbar"
|
"github.com/schollz/progressbar"
|
||||||
"github.com/schollz/tarinator-go"
|
tarinator "github.com/schollz/tarinator-go"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
@ -100,7 +102,27 @@ func NewConnection(flags *Flags) (*Connection, error) {
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Connection) cleanup() {
|
||||||
|
log.Debug("cleaning")
|
||||||
|
for id := 1; id <= 8; id++ {
|
||||||
|
os.Remove(path.Join(c.Path, c.File.Name+".enc."+strconv.Itoa(id)))
|
||||||
|
}
|
||||||
|
os.Remove(path.Join(c.Path, c.File.Name+".enc"))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Connection) Run() error {
|
func (c *Connection) Run() error {
|
||||||
|
// catch the Ctl+C
|
||||||
|
catchCtlC := make(chan os.Signal, 2)
|
||||||
|
signal.Notify(catchCtlC, os.Interrupt, syscall.SIGTERM)
|
||||||
|
go func() {
|
||||||
|
<-catchCtlC
|
||||||
|
c.cleanup()
|
||||||
|
fmt.Println("\nExiting")
|
||||||
|
os.Exit(1)
|
||||||
|
}()
|
||||||
|
defer c.cleanup()
|
||||||
|
|
||||||
forceSingleThreaded := false
|
forceSingleThreaded := false
|
||||||
if c.IsSender {
|
if c.IsSender {
|
||||||
fsize, err := FileSize(path.Join(c.File.Path, c.File.Name))
|
fsize, err := FileSize(path.Join(c.File.Path, c.File.Name))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue