2016-07-04 10:40:29 +00:00
|
|
|
// Copyright (C) 2014 The Syncthing Authors.
|
|
|
|
|
//
|
|
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
2017-02-09 07:52:18 +01:00
|
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
2016-07-04 10:40:29 +00:00
|
|
|
|
|
|
|
|
package db
|
|
|
|
|
|
|
|
|
|
import (
|
2018-10-10 11:48:21 +02:00
|
|
|
"bytes"
|
2016-07-04 10:40:29 +00:00
|
|
|
"fmt"
|
2020-09-04 11:09:36 +02:00
|
|
|
"strings"
|
2016-07-04 10:40:29 +00:00
|
|
|
|
2024-12-01 16:50:17 +01:00
|
|
|
"google.golang.org/protobuf/proto"
|
|
|
|
|
|
|
|
|
|
"github.com/syncthing/syncthing/internal/gen/dbproto"
|
2016-07-04 10:40:29 +00:00
|
|
|
"github.com/syncthing/syncthing/lib/protocol"
|
|
|
|
|
)
|
|
|
|
|
|
2024-12-01 16:50:17 +01:00
|
|
|
type CountsSet struct {
|
|
|
|
|
Counts []Counts
|
|
|
|
|
Created int64 // unix nanos
|
2022-09-14 09:50:55 +02:00
|
|
|
}
|
|
|
|
|
|
2024-12-01 16:50:17 +01:00
|
|
|
type Counts struct {
|
|
|
|
|
Files int
|
|
|
|
|
Directories int
|
|
|
|
|
Symlinks int
|
|
|
|
|
Deleted int
|
|
|
|
|
Bytes int64
|
|
|
|
|
Sequence int64 // zero for the global state
|
|
|
|
|
DeviceID protocol.DeviceID // device ID for remote devices, or special values for local/global
|
|
|
|
|
LocalFlags uint32 // the local flag for this count bucket
|
2023-03-06 15:37:15 +01:00
|
|
|
}
|
|
|
|
|
|
2024-12-01 16:50:17 +01:00
|
|
|
func (c Counts) toWire() *dbproto.Counts {
|
|
|
|
|
return &dbproto.Counts{
|
|
|
|
|
Files: int32(c.Files),
|
|
|
|
|
Directories: int32(c.Directories),
|
|
|
|
|
Symlinks: int32(c.Symlinks),
|
|
|
|
|
Deleted: int32(c.Deleted),
|
|
|
|
|
Bytes: c.Bytes,
|
|
|
|
|
Sequence: c.Sequence,
|
|
|
|
|
DeviceId: c.DeviceID[:],
|
|
|
|
|
LocalFlags: c.LocalFlags,
|
2020-04-02 16:14:25 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-01 16:50:17 +01:00
|
|
|
func countsFromWire(w *dbproto.Counts) Counts {
|
|
|
|
|
return Counts{
|
|
|
|
|
Files: int(w.Files),
|
|
|
|
|
Directories: int(w.Directories),
|
|
|
|
|
Symlinks: int(w.Symlinks),
|
|
|
|
|
Deleted: int(w.Deleted),
|
|
|
|
|
Bytes: w.Bytes,
|
|
|
|
|
Sequence: w.Sequence,
|
|
|
|
|
DeviceID: protocol.DeviceID(w.DeviceId),
|
|
|
|
|
LocalFlags: w.LocalFlags,
|
2020-02-10 10:48:30 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-12 11:15:57 +03:00
|
|
|
func (c Counts) Add(other Counts) Counts {
|
|
|
|
|
return Counts{
|
|
|
|
|
Files: c.Files + other.Files,
|
|
|
|
|
Directories: c.Directories + other.Directories,
|
|
|
|
|
Symlinks: c.Symlinks + other.Symlinks,
|
|
|
|
|
Deleted: c.Deleted + other.Deleted,
|
|
|
|
|
Bytes: c.Bytes + other.Bytes,
|
|
|
|
|
Sequence: c.Sequence + other.Sequence,
|
2024-12-01 16:50:17 +01:00
|
|
|
DeviceID: protocol.EmptyDeviceID,
|
2018-07-12 11:15:57 +03:00
|
|
|
LocalFlags: c.LocalFlags | other.LocalFlags,
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-10-10 11:48:21 +02:00
|
|
|
|
2020-10-02 07:07:05 +01:00
|
|
|
func (c Counts) TotalItems() int {
|
2018-12-11 09:59:04 +01:00
|
|
|
return c.Files + c.Directories + c.Symlinks + c.Deleted
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-04 11:09:36 +02:00
|
|
|
func (c Counts) String() string {
|
|
|
|
|
var flags strings.Builder
|
|
|
|
|
if c.LocalFlags&needFlag != 0 {
|
|
|
|
|
flags.WriteString("Need")
|
|
|
|
|
}
|
|
|
|
|
if c.LocalFlags&protocol.FlagLocalIgnored != 0 {
|
|
|
|
|
flags.WriteString("Ignored")
|
|
|
|
|
}
|
|
|
|
|
if c.LocalFlags&protocol.FlagLocalMustRescan != 0 {
|
|
|
|
|
flags.WriteString("Rescan")
|
|
|
|
|
}
|
|
|
|
|
if c.LocalFlags&protocol.FlagLocalReceiveOnly != 0 {
|
|
|
|
|
flags.WriteString("Recvonly")
|
|
|
|
|
}
|
|
|
|
|
if c.LocalFlags&protocol.FlagLocalUnsupported != 0 {
|
|
|
|
|
flags.WriteString("Unsupported")
|
|
|
|
|
}
|
|
|
|
|
if c.LocalFlags != 0 {
|
|
|
|
|
flags.WriteString(fmt.Sprintf("(%x)", c.LocalFlags))
|
|
|
|
|
}
|
|
|
|
|
if flags.Len() == 0 {
|
|
|
|
|
flags.WriteString("---")
|
|
|
|
|
}
|
2024-12-01 16:50:17 +01:00
|
|
|
return fmt.Sprintf("{Device:%v, Files:%d, Dirs:%d, Symlinks:%d, Del:%d, Bytes:%d, Seq:%d, Flags:%s}", c.DeviceID, c.Files, c.Directories, c.Symlinks, c.Deleted, c.Bytes, c.Sequence, flags.String())
|
2020-09-04 11:09:36 +02:00
|
|
|
}
|
|
|
|
|
|
2020-05-11 15:07:06 +02:00
|
|
|
// Equal compares the numbers only, not sequence/dev/flags.
|
|
|
|
|
func (c Counts) Equal(o Counts) bool {
|
|
|
|
|
return c.Files == o.Files && c.Directories == o.Directories && c.Symlinks == o.Symlinks && c.Deleted == o.Deleted && c.Bytes == o.Bytes
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-10 11:48:21 +02:00
|
|
|
// update brings the VersionList up to date with file. It returns the updated
|
2020-05-30 09:50:23 +02:00
|
|
|
// VersionList, a device that has the global/newest version, a device that previously
|
|
|
|
|
// had the global/newest version, a boolean indicating if the global version has
|
|
|
|
|
// changed and if any error occurred (only possible in db interaction).
|
2024-12-01 16:50:17 +01:00
|
|
|
func vlUpdate(vl *dbproto.VersionList, folder, device []byte, file protocol.FileInfo, t readOnlyTransaction) (*dbproto.FileVersion, *dbproto.FileVersion, *dbproto.FileVersion, bool, bool, bool, error) {
|
|
|
|
|
if len(vl.Versions) == 0 {
|
2020-05-30 09:50:23 +02:00
|
|
|
nv := newFileVersion(device, file.FileVersion(), file.IsInvalid(), file.IsDeleted())
|
2024-12-01 16:50:17 +01:00
|
|
|
vl.Versions = append(vl.Versions, nv)
|
|
|
|
|
return nv, nil, nil, false, false, true, nil
|
2020-05-30 09:50:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get the current global (before updating)
|
2024-12-01 16:50:17 +01:00
|
|
|
oldFV, haveOldGlobal := vlGetGlobal(vl)
|
|
|
|
|
oldFV = fvCopy(oldFV)
|
2020-05-30 09:50:23 +02:00
|
|
|
|
|
|
|
|
// Remove ourselves first
|
2024-12-01 16:50:17 +01:00
|
|
|
removedFV, haveRemoved, _ := vlPop(vl, device)
|
2022-04-27 20:32:44 +02:00
|
|
|
// Find position and insert the file
|
2024-12-01 16:50:17 +01:00
|
|
|
err := vlInsert(vl, folder, device, file, t)
|
2020-05-30 09:50:23 +02:00
|
|
|
if err != nil {
|
2024-12-01 16:50:17 +01:00
|
|
|
return nil, nil, nil, false, false, false, err
|
2020-05-30 09:50:23 +02:00
|
|
|
}
|
|
|
|
|
|
2024-12-01 16:50:17 +01:00
|
|
|
newFV, _ := vlGetGlobal(vl) // We just inserted something above, can't be empty
|
2018-10-10 11:48:21 +02:00
|
|
|
|
2020-05-30 09:50:23 +02:00
|
|
|
if !haveOldGlobal {
|
2024-12-01 16:50:17 +01:00
|
|
|
return newFV, nil, removedFV, false, haveRemoved, true, nil
|
2018-10-10 11:48:21 +02:00
|
|
|
}
|
2020-05-30 09:50:23 +02:00
|
|
|
|
|
|
|
|
globalChanged := true
|
2024-12-01 16:50:17 +01:00
|
|
|
if fvIsInvalid(oldFV) == fvIsInvalid(newFV) && protocol.VectorFromWire(oldFV.Version).Equal(protocol.VectorFromWire(newFV.Version)) {
|
2020-05-30 09:50:23 +02:00
|
|
|
globalChanged = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return newFV, oldFV, removedFV, true, haveRemoved, globalChanged, nil
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-01 16:50:17 +01:00
|
|
|
func vlInsert(vl *dbproto.VersionList, folder, device []byte, file protocol.FileInfo, t readOnlyTransaction) error {
|
2020-05-30 09:50:23 +02:00
|
|
|
var added bool
|
|
|
|
|
var err error
|
2018-10-10 12:43:07 +02:00
|
|
|
i := 0
|
2024-12-01 16:50:17 +01:00
|
|
|
for ; i < len(vl.Versions); i++ {
|
2020-05-30 09:50:23 +02:00
|
|
|
// Insert our new version
|
2024-12-01 16:50:17 +01:00
|
|
|
added, err = vlCheckInsertAt(vl, i, folder, device, file, t)
|
2020-05-30 09:50:23 +02:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if added {
|
|
|
|
|
break
|
2018-10-10 11:48:21 +02:00
|
|
|
}
|
|
|
|
|
}
|
2024-12-01 16:50:17 +01:00
|
|
|
if i == len(vl.Versions) {
|
2020-05-30 09:50:23 +02:00
|
|
|
// Append to the end
|
2024-12-01 16:50:17 +01:00
|
|
|
vl.Versions = append(vl.Versions, newFileVersion(device, file.FileVersion(), file.IsInvalid(), file.IsDeleted()))
|
2020-05-30 09:50:23 +02:00
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2018-10-10 11:48:21 +02:00
|
|
|
|
2024-12-01 16:50:17 +01:00
|
|
|
func vlInsertAt(vl *dbproto.VersionList, i int, v *dbproto.FileVersion) {
|
|
|
|
|
vl.Versions = append(vl.Versions, &dbproto.FileVersion{})
|
|
|
|
|
copy(vl.Versions[i+1:], vl.Versions[i:])
|
|
|
|
|
vl.Versions[i] = v
|
2020-05-30 09:50:23 +02:00
|
|
|
}
|
2018-10-10 11:48:21 +02:00
|
|
|
|
2020-09-04 14:13:38 +02:00
|
|
|
// pop removes the given device from the VersionList and returns the FileVersion
|
|
|
|
|
// before removing the device, whether it was found/removed at all and whether
|
2020-05-30 09:50:23 +02:00
|
|
|
// the global changed in the process.
|
2024-12-01 16:50:17 +01:00
|
|
|
func vlPop(vl *dbproto.VersionList, device []byte) (*dbproto.FileVersion, bool, bool) {
|
|
|
|
|
invDevice, i, j, ok := vlFindDevice(vl, device)
|
2020-05-30 09:50:23 +02:00
|
|
|
if !ok {
|
2024-12-01 16:50:17 +01:00
|
|
|
return nil, false, false
|
2020-05-30 09:50:23 +02:00
|
|
|
}
|
2024-12-01 16:50:17 +01:00
|
|
|
globalPos := vlFindGlobal(vl)
|
2020-05-30 09:50:23 +02:00
|
|
|
|
2024-12-01 16:50:17 +01:00
|
|
|
fv := vl.Versions[i]
|
|
|
|
|
if fvDeviceCount(fv) == 1 {
|
|
|
|
|
vlPopVersionAt(vl, i)
|
2022-04-27 20:32:44 +02:00
|
|
|
return fv, true, globalPos == i
|
2020-05-30 09:50:23 +02:00
|
|
|
}
|
|
|
|
|
|
2024-12-01 16:50:17 +01:00
|
|
|
oldFV := fvCopy(fv)
|
2020-05-30 09:50:23 +02:00
|
|
|
if invDevice {
|
2024-12-01 16:50:17 +01:00
|
|
|
vl.Versions[i].InvalidDevices = popDeviceAt(vl.Versions[i].InvalidDevices, j)
|
2022-04-27 20:32:44 +02:00
|
|
|
return oldFV, true, false
|
2020-05-30 09:50:23 +02:00
|
|
|
}
|
2024-12-01 16:50:17 +01:00
|
|
|
vl.Versions[i].Devices = popDeviceAt(vl.Versions[i].Devices, j)
|
2020-05-30 09:50:23 +02:00
|
|
|
// If the last valid device of the previous global was removed above,
|
2021-06-17 10:15:11 +02:00
|
|
|
// the global changed.
|
2024-12-01 16:50:17 +01:00
|
|
|
return oldFV, true, len(vl.Versions[i].Devices) == 0 && globalPos == i
|
2018-10-10 11:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
2020-05-30 09:50:23 +02:00
|
|
|
// Get returns a FileVersion that contains the given device and whether it has
|
|
|
|
|
// been found at all.
|
2024-12-01 16:50:17 +01:00
|
|
|
func vlGet(vl *dbproto.VersionList, device []byte) (*dbproto.FileVersion, bool) {
|
|
|
|
|
_, i, _, ok := vlFindDevice(vl, device)
|
2020-05-30 09:50:23 +02:00
|
|
|
if !ok {
|
2024-12-01 16:50:17 +01:00
|
|
|
return &dbproto.FileVersion{}, false
|
2020-05-30 09:50:23 +02:00
|
|
|
}
|
2024-12-01 16:50:17 +01:00
|
|
|
return vl.Versions[i], true
|
2018-10-10 11:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
2020-05-30 09:50:23 +02:00
|
|
|
// GetGlobal returns the current global FileVersion. The returned FileVersion
|
|
|
|
|
// may be invalid, if all FileVersions are invalid. Returns false only if
|
|
|
|
|
// VersionList is empty.
|
2024-12-01 16:50:17 +01:00
|
|
|
func vlGetGlobal(vl *dbproto.VersionList) (*dbproto.FileVersion, bool) {
|
|
|
|
|
i := vlFindGlobal(vl)
|
2020-05-30 09:50:23 +02:00
|
|
|
if i == -1 {
|
2024-12-01 16:50:17 +01:00
|
|
|
return nil, false
|
2020-05-30 09:50:23 +02:00
|
|
|
}
|
2024-12-01 16:50:17 +01:00
|
|
|
return vl.Versions[i], true
|
2020-05-30 09:50:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// findGlobal returns the first version that isn't invalid, or if all versions are
|
|
|
|
|
// invalid just the first version (i.e. 0) or -1, if there's no versions at all.
|
2024-12-01 16:50:17 +01:00
|
|
|
func vlFindGlobal(vl *dbproto.VersionList) int {
|
|
|
|
|
for i := range vl.Versions {
|
|
|
|
|
if !fvIsInvalid(vl.Versions[i]) {
|
2020-05-30 09:50:23 +02:00
|
|
|
return i
|
2018-10-30 05:40:51 +01:00
|
|
|
}
|
|
|
|
|
}
|
2024-12-01 16:50:17 +01:00
|
|
|
if len(vl.Versions) == 0 {
|
2020-05-30 09:50:23 +02:00
|
|
|
return -1
|
|
|
|
|
}
|
|
|
|
|
return 0
|
2018-10-30 05:40:51 +01:00
|
|
|
}
|
|
|
|
|
|
2024-05-16 15:02:57 +08:00
|
|
|
// findDevice returns whether the device is in InvalidVersions or Versions and
|
2020-05-30 09:50:23 +02:00
|
|
|
// in InvalidDevices or Devices (true for invalid), the positions in the version
|
|
|
|
|
// and device slices and whether it has been found at all.
|
2024-12-01 16:50:17 +01:00
|
|
|
func vlFindDevice(vl *dbproto.VersionList, device []byte) (bool, int, int, bool) {
|
|
|
|
|
for i, v := range vl.Versions {
|
2020-05-30 09:50:23 +02:00
|
|
|
if j := deviceIndex(v.Devices, device); j != -1 {
|
|
|
|
|
return false, i, j, true
|
2018-10-10 11:48:21 +02:00
|
|
|
}
|
2020-05-30 09:50:23 +02:00
|
|
|
if j := deviceIndex(v.InvalidDevices, device); j != -1 {
|
|
|
|
|
return true, i, j, true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false, -1, -1, false
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-01 16:50:17 +01:00
|
|
|
func vlPopVersionAt(vl *dbproto.VersionList, i int) {
|
|
|
|
|
vl.Versions = append(vl.Versions[:i], vl.Versions[i+1:]...)
|
2020-05-30 09:50:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// checkInsertAt determines if the given device and associated file should be
|
|
|
|
|
// inserted into the FileVersion at position i or into a new FileVersion at
|
|
|
|
|
// position i.
|
2024-12-01 16:50:17 +01:00
|
|
|
func vlCheckInsertAt(vl *dbproto.VersionList, i int, folder, device []byte, file protocol.FileInfo, t readOnlyTransaction) (bool, error) {
|
|
|
|
|
fv := vl.Versions[i]
|
|
|
|
|
ordering := protocol.VectorFromWire(fv.Version).Compare(file.FileVersion())
|
2020-05-30 09:50:23 +02:00
|
|
|
if ordering == protocol.Equal {
|
|
|
|
|
if !file.IsInvalid() {
|
2024-12-01 16:50:17 +01:00
|
|
|
fv.Devices = append(fv.Devices, device)
|
2020-05-30 09:50:23 +02:00
|
|
|
} else {
|
2024-12-01 16:50:17 +01:00
|
|
|
fv.InvalidDevices = append(fv.InvalidDevices, device)
|
2020-05-30 09:50:23 +02:00
|
|
|
}
|
|
|
|
|
return true, nil
|
|
|
|
|
}
|
2024-12-01 16:50:17 +01:00
|
|
|
existingDevice, _ := fvFirstDevice(fv)
|
|
|
|
|
insert, err := shouldInsertBefore(ordering, folder, existingDevice, fvIsInvalid(fv), file, t)
|
2020-05-30 09:50:23 +02:00
|
|
|
if err != nil {
|
|
|
|
|
return false, err
|
|
|
|
|
}
|
|
|
|
|
if insert {
|
2024-12-01 16:50:17 +01:00
|
|
|
vlInsertAt(vl, i, newFileVersion(device, file.FileVersion(), file.IsInvalid(), file.IsDeleted()))
|
2020-05-30 09:50:23 +02:00
|
|
|
return true, nil
|
|
|
|
|
}
|
|
|
|
|
return false, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// shouldInsertBefore determines whether the file comes before an existing
|
|
|
|
|
// entry, given the version ordering (existing compared to new one), existing
|
|
|
|
|
// device and if the existing version is invalid.
|
2024-12-01 16:50:17 +01:00
|
|
|
func shouldInsertBefore(ordering protocol.Ordering, folder, existingDevice []byte, existingInvalid bool, file protocol.FileInfo, t readOnlyTransaction) (bool, error) {
|
2020-05-30 09:50:23 +02:00
|
|
|
switch ordering {
|
|
|
|
|
case protocol.Lesser:
|
|
|
|
|
// The version at this point in the list is lesser
|
|
|
|
|
// ("older") than us. We insert ourselves in front of it.
|
|
|
|
|
return true, nil
|
|
|
|
|
|
|
|
|
|
case protocol.ConcurrentLesser, protocol.ConcurrentGreater:
|
|
|
|
|
// The version in conflict with us.
|
|
|
|
|
// Check if we can shortcut due to one being invalid.
|
|
|
|
|
if existingInvalid != file.IsInvalid() {
|
|
|
|
|
return existingInvalid, nil
|
|
|
|
|
}
|
|
|
|
|
// We must pull the actual file metadata to determine who wins.
|
|
|
|
|
// If we win, we insert ourselves in front of the loser here.
|
|
|
|
|
// (The "Lesser" and "Greater" in the condition above is just
|
|
|
|
|
// based on the device IDs in the version vector, which is not
|
|
|
|
|
// the only thing we use to determine the winner.)
|
|
|
|
|
of, ok, err := t.getFile(folder, existingDevice, []byte(file.FileName()))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return false, err
|
|
|
|
|
}
|
|
|
|
|
// A surprise missing file entry here is counted as a win for us.
|
|
|
|
|
if !ok {
|
|
|
|
|
return true, nil
|
|
|
|
|
}
|
2024-12-01 16:50:17 +01:00
|
|
|
if file.WinsConflict(of) {
|
2020-05-30 09:50:23 +02:00
|
|
|
return true, nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func deviceIndex(devices [][]byte, device []byte) int {
|
|
|
|
|
for i, dev := range devices {
|
|
|
|
|
if bytes.Equal(device, dev) {
|
|
|
|
|
return i
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return -1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func popDeviceAt(devices [][]byte, i int) [][]byte {
|
|
|
|
|
return append(devices[:i], devices[i+1:]...)
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-01 16:50:17 +01:00
|
|
|
func newFileVersion(device []byte, version protocol.Vector, invalid, deleted bool) *dbproto.FileVersion {
|
|
|
|
|
fv := &dbproto.FileVersion{
|
|
|
|
|
Version: version.ToWire(),
|
2020-05-30 09:50:23 +02:00
|
|
|
Deleted: deleted,
|
|
|
|
|
}
|
|
|
|
|
if invalid {
|
|
|
|
|
fv.InvalidDevices = [][]byte{device}
|
|
|
|
|
} else {
|
|
|
|
|
fv.Devices = [][]byte{device}
|
|
|
|
|
}
|
|
|
|
|
return fv
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-01 16:50:17 +01:00
|
|
|
func fvFirstDevice(fv *dbproto.FileVersion) ([]byte, bool) {
|
2020-05-30 09:50:23 +02:00
|
|
|
if len(fv.Devices) != 0 {
|
|
|
|
|
return fv.Devices[0], true
|
|
|
|
|
}
|
|
|
|
|
if len(fv.InvalidDevices) != 0 {
|
|
|
|
|
return fv.InvalidDevices[0], true
|
|
|
|
|
}
|
|
|
|
|
return nil, false
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-01 16:50:17 +01:00
|
|
|
func fvIsInvalid(fv *dbproto.FileVersion) bool {
|
|
|
|
|
return fv == nil || len(fv.Devices) == 0
|
2020-05-30 09:50:23 +02:00
|
|
|
}
|
2018-10-10 11:48:21 +02:00
|
|
|
|
2024-12-01 16:50:17 +01:00
|
|
|
func fvDeviceCount(fv *dbproto.FileVersion) int {
|
2020-05-30 09:50:23 +02:00
|
|
|
return len(fv.Devices) + len(fv.InvalidDevices)
|
2018-10-10 11:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
2024-12-01 16:50:17 +01:00
|
|
|
func fvCopy(fv *dbproto.FileVersion) *dbproto.FileVersion {
|
|
|
|
|
return proto.Clone(fv).(*dbproto.FileVersion)
|
2020-09-04 14:13:38 +02:00
|
|
|
}
|