mirror of
https://github.com/rclone/rclone.git
synced 2025-02-23 05:51:36 +01:00
Protect accounting from being closed twice
This commit is contained in:
parent
4ed8836a71
commit
ed72c678f8
@ -256,6 +256,7 @@ type Account struct {
|
|||||||
lpTime time.Time // Time of last average measurement
|
lpTime time.Time // Time of last average measurement
|
||||||
lpBytes int // Number of bytes read since last measurement
|
lpBytes int // Number of bytes read since last measurement
|
||||||
avg ewma.MovingAverage // Moving average of last few measurements
|
avg ewma.MovingAverage // Moving average of last few measurements
|
||||||
|
closed bool // set if the file is closed
|
||||||
exit chan struct{} // channel that will be closed when transfer is finished
|
exit chan struct{} // channel that will be closed when transfer is finished
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,9 +409,13 @@ func (file *Account) String() string {
|
|||||||
|
|
||||||
// Close the object
|
// Close the object
|
||||||
func (file *Account) Close() error {
|
func (file *Account) Close() error {
|
||||||
close(file.exit)
|
|
||||||
file.mu.Lock()
|
file.mu.Lock()
|
||||||
defer file.mu.Unlock()
|
defer file.mu.Unlock()
|
||||||
|
if file.closed {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
file.closed = true
|
||||||
|
close(file.exit)
|
||||||
Stats.inProgress.clear(file.name)
|
Stats.inProgress.clear(file.name)
|
||||||
return file.in.Close()
|
return file.in.Close()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user