-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfeedx.go
More file actions
42 lines (34 loc) · 1.07 KB
/
feedx.go
File metadata and controls
42 lines (34 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package feedx
import (
"context"
"errors"
"strconv"
"github.com/bsm/bfs"
)
// ErrNotModified is used to signal that something has not been modified.
var ErrNotModified = errors.New("feedx: not modified")
const metaVersion = "X-Feedx-Version"
func fetchRemoteVersion(ctx context.Context, obj *bfs.Object) (int64, error) {
info, err := obj.Head(ctx)
if err == bfs.ErrNotFound {
return 0, nil
} else if err != nil {
return 0, err
}
version, _ := strconv.ParseInt(info.Metadata.Get(metaVersion), 10, 64)
return version, nil
}
// Status is returned by sync processes.
type Status struct {
// Skipped indicates the the sync was skipped, because there were no new changes.
Skipped bool
// LocalVersion indicates the local version before sync.
LocalVersion int64
// RemoteVersion indicates the remote version before sync.
RemoteVersion int64
// NumItems returns the number of items processed, either read of written.
NumItems int64
}
func skipSync(srcVersion, targetVersion int64) bool {
return (srcVersion != 0 || targetVersion != 0) && srcVersion <= targetVersion
}