2016-07-04 03:40:29 -07: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-08 23:52:18 -07:00
|
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
2016-07-04 03:40:29 -07:00
|
|
|
|
|
|
|
//go:generate go run ../../script/protofmt.go structs.proto
|
2017-01-02 17:16:21 -07:00
|
|
|
//go:generate protoc -I ../../../../../ -I ../../vendor/ -I ../../vendor/github.com/gogo/protobuf/protobuf -I . --gogofast_out=. structs.proto
|
2016-07-04 03:40:29 -07:00
|
|
|
|
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-08-06 06:05:59 -07:00
|
|
|
"time"
|
2016-07-04 03:40:29 -07:00
|
|
|
|
|
|
|
"github.com/syncthing/syncthing/lib/protocol"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (f FileInfoTruncated) String() string {
|
2018-06-24 00:50:18 -07:00
|
|
|
switch f.Type {
|
|
|
|
case protocol.FileInfoTypeDirectory:
|
|
|
|
return fmt.Sprintf("Directory{Name:%q, Sequence:%d, Permissions:0%o, ModTime:%v, Version:%v, Deleted:%v, Invalid:%v, LocalFlags:0x%x, NoPermissions:%v}",
|
|
|
|
f.Name, f.Sequence, f.Permissions, f.ModTime(), f.Version, f.Deleted, f.RawInvalid, f.LocalFlags, f.NoPermissions)
|
|
|
|
case protocol.FileInfoTypeFile:
|
|
|
|
return fmt.Sprintf("File{Name:%q, Sequence:%d, Permissions:0%o, ModTime:%v, Version:%v, Length:%d, Deleted:%v, Invalid:%v, LocalFlags:0x%x, NoPermissions:%v, BlockSize:%d}",
|
|
|
|
f.Name, f.Sequence, f.Permissions, f.ModTime(), f.Version, f.Size, f.Deleted, f.RawInvalid, f.LocalFlags, f.NoPermissions, f.RawBlockSize)
|
|
|
|
case protocol.FileInfoTypeSymlink, protocol.FileInfoTypeDeprecatedSymlinkDirectory, protocol.FileInfoTypeDeprecatedSymlinkFile:
|
|
|
|
return fmt.Sprintf("Symlink{Name:%q, Type:%v, Sequence:%d, Version:%v, Deleted:%v, Invalid:%v, LocalFlags:0x%x, NoPermissions:%v, SymlinkTarget:%q}",
|
|
|
|
f.Name, f.Type, f.Sequence, f.Version, f.Deleted, f.RawInvalid, f.LocalFlags, f.NoPermissions, f.SymlinkTarget)
|
|
|
|
default:
|
|
|
|
panic("mystery file type detected")
|
|
|
|
}
|
2016-07-04 03:40:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f FileInfoTruncated) IsDeleted() bool {
|
|
|
|
return f.Deleted
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f FileInfoTruncated) IsInvalid() bool {
|
2018-06-24 00:50:18 -07:00
|
|
|
return f.RawInvalid || f.LocalFlags&protocol.LocalInvalidFlags != 0
|
|
|
|
}
|
|
|
|
|
2018-07-12 01:15:57 -07:00
|
|
|
func (f FileInfoTruncated) IsUnsupported() bool {
|
|
|
|
return f.LocalFlags&protocol.FlagLocalUnsupported != 0
|
|
|
|
}
|
|
|
|
|
2018-06-24 00:50:18 -07:00
|
|
|
func (f FileInfoTruncated) IsIgnored() bool {
|
|
|
|
return f.LocalFlags&protocol.FlagLocalIgnored != 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f FileInfoTruncated) MustRescan() bool {
|
|
|
|
return f.LocalFlags&protocol.FlagLocalMustRescan != 0
|
2016-07-04 03:40:29 -07:00
|
|
|
}
|
|
|
|
|
2018-07-12 01:15:57 -07:00
|
|
|
func (f FileInfoTruncated) IsReceiveOnlyChanged() bool {
|
|
|
|
return f.LocalFlags&protocol.FlagLocalReceiveOnly != 0
|
|
|
|
}
|
|
|
|
|
2016-07-04 03:40:29 -07:00
|
|
|
func (f FileInfoTruncated) IsDirectory() bool {
|
|
|
|
return f.Type == protocol.FileInfoTypeDirectory
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f FileInfoTruncated) IsSymlink() bool {
|
|
|
|
switch f.Type {
|
2017-02-07 01:34:24 -07:00
|
|
|
case protocol.FileInfoTypeSymlink, protocol.FileInfoTypeDeprecatedSymlinkDirectory, protocol.FileInfoTypeDeprecatedSymlinkFile:
|
2016-07-04 03:40:29 -07:00
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-25 01:32:35 -07:00
|
|
|
func (f FileInfoTruncated) ShouldConflict() bool {
|
|
|
|
return f.LocalFlags&protocol.LocalConflictFlags != 0
|
|
|
|
}
|
|
|
|
|
2016-07-04 03:40:29 -07:00
|
|
|
func (f FileInfoTruncated) HasPermissionBits() bool {
|
|
|
|
return !f.NoPermissions
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f FileInfoTruncated) FileSize() int64 {
|
2016-09-01 23:45:46 -07:00
|
|
|
if f.Deleted {
|
|
|
|
return 0
|
|
|
|
}
|
2016-12-09 02:38:36 -07:00
|
|
|
if f.IsDirectory() || f.IsSymlink() {
|
2016-09-01 23:45:46 -07:00
|
|
|
return protocol.SyntheticDirectorySize
|
2016-07-04 03:40:29 -07:00
|
|
|
}
|
|
|
|
return f.Size
|
|
|
|
}
|
|
|
|
|
2018-04-16 11:08:50 -07:00
|
|
|
func (f FileInfoTruncated) BlockSize() int {
|
|
|
|
if f.RawBlockSize == 0 {
|
|
|
|
return protocol.MinBlockSize
|
|
|
|
}
|
|
|
|
return int(f.RawBlockSize)
|
|
|
|
}
|
|
|
|
|
2016-07-04 03:40:29 -07:00
|
|
|
func (f FileInfoTruncated) FileName() string {
|
|
|
|
return f.Name
|
|
|
|
}
|
2016-08-06 06:05:59 -07:00
|
|
|
|
2018-07-12 01:15:57 -07:00
|
|
|
func (f FileInfoTruncated) FileLocalFlags() uint32 {
|
|
|
|
return f.LocalFlags
|
|
|
|
}
|
|
|
|
|
2016-08-06 06:05:59 -07:00
|
|
|
func (f FileInfoTruncated) ModTime() time.Time {
|
|
|
|
return time.Unix(f.ModifiedS, int64(f.ModifiedNs))
|
|
|
|
}
|
2017-11-11 12:18:17 -07:00
|
|
|
|
2017-12-14 02:51:17 -07:00
|
|
|
func (f FileInfoTruncated) SequenceNo() int64 {
|
|
|
|
return f.Sequence
|
|
|
|
}
|
|
|
|
|
2018-06-02 06:08:32 -07:00
|
|
|
func (f FileInfoTruncated) FileVersion() protocol.Vector {
|
|
|
|
return f.Version
|
|
|
|
}
|
|
|
|
|
2018-06-24 00:50:18 -07:00
|
|
|
func (f FileInfoTruncated) ConvertToIgnoredFileInfo(by protocol.ShortID) protocol.FileInfo {
|
2017-11-11 12:18:17 -07:00
|
|
|
return protocol.FileInfo{
|
2018-04-16 11:08:50 -07:00
|
|
|
Name: f.Name,
|
|
|
|
Type: f.Type,
|
|
|
|
ModifiedS: f.ModifiedS,
|
|
|
|
ModifiedNs: f.ModifiedNs,
|
2018-06-24 00:50:18 -07:00
|
|
|
ModifiedBy: by,
|
2018-04-16 11:08:50 -07:00
|
|
|
Version: f.Version,
|
|
|
|
RawBlockSize: f.RawBlockSize,
|
2018-06-24 00:50:18 -07:00
|
|
|
LocalFlags: protocol.FlagLocalIgnored,
|
2017-11-11 12:18:17 -07:00
|
|
|
}
|
|
|
|
}
|
2018-07-12 01:15:57 -07: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,
|
|
|
|
DeviceID: protocol.EmptyDeviceID[:],
|
|
|
|
LocalFlags: c.LocalFlags | other.LocalFlags,
|
|
|
|
}
|
|
|
|
}
|