diff --git a/cmd/syncthing/gui.go b/cmd/syncthing/gui.go index 682c88780..21020e7fb 100644 --- a/cmd/syncthing/gui.go +++ b/cmd/syncthing/gui.go @@ -810,8 +810,7 @@ func toNeedSlice(fs []db.FileInfoTruncated) []map[string]interface{} { "Modified": file.Modified, "Version": file.Version, "LocalVersion": file.LocalVersion, - "NumBlocks": file.NumBlocks, - "Size": db.BlocksToSize(int(file.NumBlocks)), + "Size": file.Size(), } } return output diff --git a/internal/db/truncated.go b/internal/db/truncated.go index 041bf5452..35210ac67 100644 --- a/internal/db/truncated.go +++ b/internal/db/truncated.go @@ -13,69 +13,33 @@ // You should have received a copy of the GNU General Public License along // with this program. If not, see . -//go:generate -command genxdr go run ../../Godeps/_workspace/src/github.com/calmh/xdr/cmd/genxdr/main.go -//go:generate genxdr -o truncated_xdr.go truncated.go - package db -import ( - "fmt" +import "github.com/syncthing/protocol" - "github.com/syncthing/protocol" -) - -// Used for unmarshalling a FileInfo structure but skipping the block list. type FileInfoTruncated struct { - Name string // max:8192 - Flags uint32 - Modified int64 - Version int64 - LocalVersion int64 - NumBlocks int32 + protocol.FileInfo + ActualSize int64 } func ToTruncated(file protocol.FileInfo) FileInfoTruncated { - return FileInfoTruncated{ - Name: file.Name, - Flags: file.Flags, - Modified: file.Modified, - Version: file.Version, - LocalVersion: file.LocalVersion, - NumBlocks: int32(len(file.Blocks)), + t := FileInfoTruncated{ + FileInfo: file, + ActualSize: file.Size(), } + t.FileInfo.Blocks = nil + return t } -func (f FileInfoTruncated) String() string { - return fmt.Sprintf("File{Name:%q, Flags:0%o, Modified:%d, Version:%d, Size:%d, NumBlocks:%d}", - f.Name, f.Flags, f.Modified, f.Version, f.Size(), f.NumBlocks) +func (f *FileInfoTruncated) UnmarshalXDR(bs []byte) error { + err := f.FileInfo.UnmarshalXDR(bs) + f.ActualSize = f.FileInfo.Size() + f.FileInfo.Blocks = nil + return err } -// Returns a statistical guess on the size, not the exact figure func (f FileInfoTruncated) Size() int64 { - if f.IsDeleted() || f.IsDirectory() { - return 128 - } - return BlocksToSize(int(f.NumBlocks)) -} - -func (f FileInfoTruncated) IsDeleted() bool { - return f.Flags&protocol.FlagDeleted != 0 -} - -func (f FileInfoTruncated) IsInvalid() bool { - return f.Flags&protocol.FlagInvalid != 0 -} - -func (f FileInfoTruncated) IsDirectory() bool { - return f.Flags&protocol.FlagDirectory != 0 -} - -func (f FileInfoTruncated) IsSymlink() bool { - return f.Flags&protocol.FlagSymlink != 0 -} - -func (f FileInfoTruncated) HasPermissionBits() bool { - return f.Flags&protocol.FlagNoPermBits == 0 + return f.ActualSize } func BlocksToSize(num int) int64 { diff --git a/internal/db/truncated_xdr.go b/internal/db/truncated_xdr.go deleted file mode 100644 index b3f301646..000000000 --- a/internal/db/truncated_xdr.go +++ /dev/null @@ -1,112 +0,0 @@ -// ************************************************************ -// This file is automatically generated by genxdr. Do not edit. -// ************************************************************ - -package db - -import ( - "bytes" - "io" - - "github.com/calmh/xdr" -) - -/* - -FileInfoTruncated Structure: - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -| Length of Name | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -/ / -\ Name (variable length) \ -/ / -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -| Flags | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -| | -+ Modified (64 bits) + -| | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -| | -+ Version (64 bits) + -| | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -| | -+ Local Version (64 bits) + -| | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -| Num Blocks | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - -struct FileInfoTruncated { - string Name<8192>; - unsigned int Flags; - hyper Modified; - hyper Version; - hyper LocalVersion; - int NumBlocks; -} - -*/ - -func (o FileInfoTruncated) EncodeXDR(w io.Writer) (int, error) { - var xw = xdr.NewWriter(w) - return o.encodeXDR(xw) -} - -func (o FileInfoTruncated) MarshalXDR() ([]byte, error) { - return o.AppendXDR(make([]byte, 0, 128)) -} - -func (o FileInfoTruncated) MustMarshalXDR() []byte { - bs, err := o.MarshalXDR() - if err != nil { - panic(err) - } - return bs -} - -func (o FileInfoTruncated) AppendXDR(bs []byte) ([]byte, error) { - var aw = xdr.AppendWriter(bs) - var xw = xdr.NewWriter(&aw) - _, err := o.encodeXDR(xw) - return []byte(aw), err -} - -func (o FileInfoTruncated) encodeXDR(xw *xdr.Writer) (int, error) { - if l := len(o.Name); l > 8192 { - return xw.Tot(), xdr.ElementSizeExceeded("Name", l, 8192) - } - xw.WriteString(o.Name) - xw.WriteUint32(o.Flags) - xw.WriteUint64(uint64(o.Modified)) - xw.WriteUint64(uint64(o.Version)) - xw.WriteUint64(uint64(o.LocalVersion)) - xw.WriteUint32(uint32(o.NumBlocks)) - return xw.Tot(), xw.Error() -} - -func (o *FileInfoTruncated) DecodeXDR(r io.Reader) error { - xr := xdr.NewReader(r) - return o.decodeXDR(xr) -} - -func (o *FileInfoTruncated) UnmarshalXDR(bs []byte) error { - var br = bytes.NewReader(bs) - var xr = xdr.NewReader(br) - return o.decodeXDR(xr) -} - -func (o *FileInfoTruncated) decodeXDR(xr *xdr.Reader) error { - o.Name = xr.ReadStringMax(8192) - o.Flags = xr.ReadUint32() - o.Modified = int64(xr.ReadUint64()) - o.Version = int64(xr.ReadUint64()) - o.LocalVersion = int64(xr.ReadUint64()) - o.NumBlocks = int32(xr.ReadUint32()) - return xr.Error() -}