mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-24 02:46:44 +00:00
fix(GODT-2829): Fix new sync service bugs
* Fix wrong context use for message downloads * Fix delete of sync data failing due ErrNotFound * Pre-allocate attachment data buffer before download * Fix calculation of progress if message count is higher than total
This commit is contained in:
@ -57,10 +57,20 @@ func (rep *syncReporter) OnError(ctx context.Context, err error) {
|
||||
func (rep *syncReporter) OnProgress(ctx context.Context, delta int64) {
|
||||
rep.count += delta
|
||||
|
||||
var progress float64
|
||||
|
||||
// It's possible for count to be bigger or smaller than total depending on when the sync begins and whether new
|
||||
// messages are added/removed during this period. When this happens just limited the progress to 100%.
|
||||
if rep.count > rep.total {
|
||||
progress = 1
|
||||
} else {
|
||||
progress = float64(rep.count) / float64(rep.total)
|
||||
}
|
||||
|
||||
if time.Since(rep.last) > rep.freq {
|
||||
rep.eventPublisher.PublishEvent(ctx, events.SyncProgress{
|
||||
UserID: rep.userID,
|
||||
Progress: float64(rep.count) / float64(rep.total),
|
||||
Progress: progress,
|
||||
Elapsed: time.Since(rep.start),
|
||||
Remaining: time.Since(rep.start) * time.Duration(rep.total-(rep.count+1)) / time.Duration(rep.count+1),
|
||||
})
|
||||
|
||||
@ -222,7 +222,11 @@ func (s *SyncState) loadUnsafe() error {
|
||||
func DeleteSyncState(configDir, userID string) error {
|
||||
path := getSyncConfigPath(configDir, userID)
|
||||
|
||||
return os.Remove(path)
|
||||
if err := os.Remove(path); err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func MigrateVaultSettings(
|
||||
|
||||
Reference in New Issue
Block a user