1
0
mirror of https://github.com/rclone/rclone.git synced 2025-12-06 00:03:32 +00:00

cache: use atexit for cleanup

This commit is contained in:
remusb
2018-01-30 22:35:53 +02:00
parent ed2d4ef4a2
commit b3d8b7e22e
2 changed files with 20 additions and 7 deletions

View File

@@ -561,6 +561,7 @@ type backgroundWriter struct {
stateCh chan int
running bool
notifyCh chan BackgroundUploadState
mu sync.Mutex
}
func newBackgroundWriter(f *Fs) *backgroundWriter {
@@ -575,6 +576,10 @@ func newBackgroundWriter(f *Fs) *backgroundWriter {
func (b *backgroundWriter) close() {
b.stateCh <- 2
b.mu.Lock()
defer b.mu.Unlock()
b.running = false
}
func (b *backgroundWriter) pause() {
@@ -585,6 +590,12 @@ func (b *backgroundWriter) play() {
b.stateCh <- 0
}
func (b *backgroundWriter) isRunning() bool {
b.mu.Lock()
defer b.mu.Unlock()
return b.running
}
func (b *backgroundWriter) notify(remote string, status int, err error) {
state := BackgroundUploadState{
Remote: remote,
@@ -601,7 +612,9 @@ func (b *backgroundWriter) notify(remote string, status int, err error) {
func (b *backgroundWriter) run() {
state := 0
for {
b.mu.Lock()
b.running = true
b.mu.Unlock()
select {
case s := <-b.stateCh:
state = s
@@ -614,7 +627,6 @@ func (b *backgroundWriter) run() {
time.Sleep(time.Millisecond * 500)
continue
case 2:
b.running = false
return
}