2015-01-09 00:19:32 -07:00
|
|
|
// Copyright (C) 2014 The Syncthing Authors.
|
|
|
|
//
|
2015-03-07 13:36:35 -07:00
|
|
|
// 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,
|
|
|
|
// You can obtain one at http://mozilla.org/MPL/2.0/.
|
2015-01-09 00:19:32 -07:00
|
|
|
|
2015-01-12 06:50:30 -07:00
|
|
|
package db
|
2015-01-09 00:19:32 -07:00
|
|
|
|
2015-10-21 14:33:04 -07:00
|
|
|
import (
|
|
|
|
"github.com/calmh/xdr"
|
|
|
|
"github.com/syncthing/syncthing/lib/protocol"
|
|
|
|
)
|
2015-01-09 00:19:32 -07:00
|
|
|
|
|
|
|
type FileInfoTruncated struct {
|
2015-02-13 05:46:49 -07:00
|
|
|
protocol.FileInfo
|
2015-01-09 00:19:32 -07:00
|
|
|
}
|
|
|
|
|
2015-10-21 14:33:04 -07:00
|
|
|
func (o *FileInfoTruncated) UnmarshalXDR(bs []byte) error {
|
2016-02-02 04:44:33 -07:00
|
|
|
return o.UnmarshalXDRFrom(&xdr.Unmarshaller{Data: bs})
|
2015-01-09 00:19:32 -07:00
|
|
|
}
|
|
|
|
|
2016-02-02 04:44:33 -07:00
|
|
|
func (o *FileInfoTruncated) UnmarshalXDRFrom(u *xdr.Unmarshaller) error {
|
|
|
|
o.Name = u.UnmarshalStringMax(8192)
|
|
|
|
o.Flags = u.UnmarshalUint32()
|
|
|
|
o.Modified = int64(u.UnmarshalUint64())
|
|
|
|
(&o.Version).UnmarshalXDRFrom(u)
|
|
|
|
o.LocalVersion = int64(u.UnmarshalUint64())
|
|
|
|
_BlocksSize := int(u.UnmarshalUint32())
|
2015-10-21 14:33:04 -07:00
|
|
|
if _BlocksSize < 0 {
|
|
|
|
return xdr.ElementSizeExceeded("Blocks", _BlocksSize, 1000000)
|
2016-02-02 04:44:33 -07:00
|
|
|
} else if _BlocksSize == 0 {
|
|
|
|
o.Blocks = nil
|
|
|
|
} else {
|
|
|
|
if _BlocksSize > 1000000 {
|
|
|
|
return xdr.ElementSizeExceeded("Blocks", _BlocksSize, 1000000)
|
|
|
|
}
|
|
|
|
for i := 0; i < _BlocksSize; i++ {
|
|
|
|
size := int64(u.UnmarshalUint32())
|
|
|
|
o.CachedSize += size
|
|
|
|
u.UnmarshalBytes()
|
|
|
|
}
|
2015-10-21 14:33:04 -07:00
|
|
|
}
|
|
|
|
|
2016-02-02 04:44:33 -07:00
|
|
|
return u.Error
|
2015-01-09 00:19:32 -07:00
|
|
|
}
|
|
|
|
|
2015-01-17 18:12:06 -07:00
|
|
|
func BlocksToSize(num int) int64 {
|
2015-01-09 00:19:32 -07:00
|
|
|
if num < 2 {
|
|
|
|
return protocol.BlockSize / 2
|
|
|
|
}
|
|
|
|
return int64(num-1)*protocol.BlockSize + protocol.BlockSize/2
|
|
|
|
}
|