mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 16:34:30 +01:00
vendor: update github.com/t3rm1n4l/go-mega - fixes #2366
This update fixes files being missing from mega directory listings.
This commit is contained in:
parent
97beff5370
commit
038ed1aaf0
2
Gopkg.lock
generated
2
Gopkg.lock
generated
@ -331,7 +331,7 @@
|
||||
branch = "master"
|
||||
name = "github.com/t3rm1n4l/go-mega"
|
||||
packages = ["."]
|
||||
revision = "3ba49835f4db01d6329782cbdc7a0a8bb3a26c5f"
|
||||
revision = "57978a63bd3f91fa7e188b751a7e7e6dd4e33813"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
|
1
vendor/github.com/t3rm1n4l/go-mega/.travis.yml
generated
vendored
1
vendor/github.com/t3rm1n4l/go-mega/.travis.yml
generated
vendored
@ -4,7 +4,6 @@ osx_image: xcode7.3
|
||||
os:
|
||||
- linux
|
||||
go:
|
||||
- 1.6.4
|
||||
- 1.7.6
|
||||
- 1.8.7
|
||||
- 1.9.5
|
||||
|
61
vendor/github.com/t3rm1n4l/go-mega/mega.go
generated
vendored
61
vendor/github.com/t3rm1n4l/go-mega/mega.go
generated
vendored
@ -112,6 +112,10 @@ type Mega struct {
|
||||
debugf func(format string, v ...interface{})
|
||||
// serialize the API requests
|
||||
apiMu sync.Mutex
|
||||
// mutex to protext waitEvents
|
||||
waitEventsMu sync.Mutex
|
||||
// Outstanding channels to close to indicate events all received
|
||||
waitEvents []chan struct{}
|
||||
}
|
||||
|
||||
// Filesystem node types
|
||||
@ -489,9 +493,61 @@ func (m *Mega) Login(email string, passwd string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
err = m.getFileSystem()
|
||||
waitEvent := m.WaitEventsStart()
|
||||
|
||||
return err
|
||||
err = m.getFileSystem()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Wait until the all the pending events have been received
|
||||
m.WaitEvents(waitEvent, 5*time.Second)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// WaitEventsStart - call this before you do the action which might
|
||||
// generate events then use the returned channel as a parameter to
|
||||
// WaitEvents to wait for the event(s) to be received.
|
||||
func (m *Mega) WaitEventsStart() <-chan struct{} {
|
||||
ch := make(chan struct{})
|
||||
m.waitEventsMu.Lock()
|
||||
m.waitEvents = append(m.waitEvents, ch)
|
||||
m.waitEventsMu.Unlock()
|
||||
return ch
|
||||
}
|
||||
|
||||
// WaitEvents waits for all outstanding events to be received for a
|
||||
// maximum of duration. eventChan should be a channel as returned
|
||||
// from WaitEventStart.
|
||||
//
|
||||
// If the timeout elapsed then it returns true otherwise false.
|
||||
func (m *Mega) WaitEvents(eventChan <-chan struct{}, duration time.Duration) (timedout bool) {
|
||||
m.debugf("Waiting for events to be finished for %v", duration)
|
||||
timer := time.NewTimer(duration)
|
||||
select {
|
||||
case <-eventChan:
|
||||
m.debugf("Events received")
|
||||
timedout = false
|
||||
case <-timer.C:
|
||||
m.debugf("Timeout waiting for events")
|
||||
timedout = true
|
||||
}
|
||||
timer.Stop()
|
||||
return timedout
|
||||
}
|
||||
|
||||
// waitEventsFire - fire the wait event
|
||||
func (m *Mega) waitEventsFire() {
|
||||
m.waitEventsMu.Lock()
|
||||
if len(m.waitEvents) > 0 {
|
||||
m.debugf("Signalling events received")
|
||||
for _, ch := range m.waitEvents {
|
||||
close(ch)
|
||||
}
|
||||
m.waitEvents = nil
|
||||
}
|
||||
m.waitEventsMu.Unlock()
|
||||
}
|
||||
|
||||
// Get user information
|
||||
@ -1616,6 +1672,7 @@ func (m *Mega) pollEvents() {
|
||||
// if wait URL is set, then fetch it and continue - we
|
||||
// don't expect anything else if we have a wait URL.
|
||||
if events.W != "" {
|
||||
m.waitEventsFire()
|
||||
if len(events.E) > 0 {
|
||||
m.logf("pollEvents: Unexpected event with w set: %s", buf)
|
||||
}
|
||||
|
41
vendor/github.com/t3rm1n4l/go-mega/mega_test.go
generated
vendored
41
vendor/github.com/t3rm1n4l/go-mega/mega_test.go
generated
vendored
@ -7,6 +7,7 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@ -360,3 +361,43 @@ func TestExportLink(t *testing.T) {
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func TestWaitEvents(t *testing.T) {
|
||||
m := &Mega{}
|
||||
m.SetLogger(t.Logf)
|
||||
m.SetDebugger(t.Logf)
|
||||
var wg sync.WaitGroup
|
||||
// in the background fire the event timer after 100mS
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
m.waitEventsFire()
|
||||
wg.Done()
|
||||
}()
|
||||
wait := func(d time.Duration, pb *bool) {
|
||||
e := m.WaitEventsStart()
|
||||
*pb = m.WaitEvents(e, d)
|
||||
wg.Done()
|
||||
}
|
||||
// wait for each event in a separate goroutine
|
||||
var b1, b2, b3 bool
|
||||
wg.Add(3)
|
||||
go wait(10*time.Second, &b1)
|
||||
go wait(2*time.Second, &b2)
|
||||
go wait(1*time.Millisecond, &b3)
|
||||
wg.Wait()
|
||||
if b1 != false {
|
||||
t.Errorf("Unexpected timeout for b1")
|
||||
}
|
||||
if b2 != false {
|
||||
t.Errorf("Unexpected timeout for b2")
|
||||
}
|
||||
if b3 != true {
|
||||
t.Errorf("Unexpected event for b3")
|
||||
}
|
||||
if m.waitEvents != nil {
|
||||
t.Errorf("Expecting waitEvents to be empty")
|
||||
}
|
||||
// Check nothing happens if we fire the event with no listeners
|
||||
m.waitEventsFire()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user