diff --git a/internal/model/model.go b/internal/model/model.go index 2927490e..5cec18cc 100644 --- a/internal/model/model.go +++ b/internal/model/model.go @@ -655,7 +655,7 @@ func (m *Model) Request(deviceID protocol.DeviceID, folder, name string, offset } lf := r.Get(protocol.LocalDeviceID, name) - if protocol.IsInvalid(lf.Flags) || protocol.IsDeleted(lf.Flags) { + if lf.IsInvalid() || lf.IsDeleted() { if debug { l.Debugf("%v REQ(in): %s: %q / %q o=%d s=%d; invalid: %v", m, deviceID, folder, name, offset, size, lf) } @@ -1085,7 +1085,7 @@ func (m *Model) ScanFolderSub(folder, sub string) error { } seenPrefix = true - if !protocol.IsDeleted(f.Flags) { + if !f.IsDeleted() { if f.IsInvalid() { return true } diff --git a/internal/model/puller.go b/internal/model/puller.go index 976995b5..3f34ef2f 100644 --- a/internal/model/puller.go +++ b/internal/model/puller.go @@ -313,10 +313,10 @@ func (p *Puller) pullerIteration(ncopiers, npullers, nfinishers int, checksum bo } switch { - case protocol.IsDeleted(file.Flags): + case file.IsDeleted(): // A deleted file or directory deletions = append(deletions, file) - case protocol.IsDirectory(file.Flags): + case file.IsDirectory(): // A new or changed directory p.handleDir(file) default: diff --git a/internal/protocol/message.go b/internal/protocol/message.go index eff837fe..5d35f17c 100644 --- a/internal/protocol/message.go +++ b/internal/protocol/message.go @@ -37,7 +37,7 @@ func (f FileInfo) String() string { } func (f FileInfo) Size() (bytes int64) { - if IsDeleted(f.Flags) || IsDirectory(f.Flags) { + if f.IsDeleted() || f.IsDirectory() { return 128 } for _, b := range f.Blocks { @@ -47,15 +47,19 @@ func (f FileInfo) Size() (bytes int64) { } func (f FileInfo) IsDeleted() bool { - return IsDeleted(f.Flags) + return f.Flags&FlagDeleted != 0 } func (f FileInfo) IsInvalid() bool { - return IsInvalid(f.Flags) + return f.Flags&FlagInvalid != 0 } func (f FileInfo) IsDirectory() bool { - return IsDirectory(f.Flags) + return f.Flags&FlagDirectory != 0 +} + +func (f FileInfo) HasPermissionBits() bool { + return f.Flags&FlagNoPermBits == 0 } // Used for unmarshalling a FileInfo structure but skipping the actual block list @@ -75,7 +79,7 @@ func (f FileInfoTruncated) String() string { // Returns a statistical guess on the size, not the exact figure func (f FileInfoTruncated) Size() int64 { - if IsDeleted(f.Flags) || IsDirectory(f.Flags) { + if f.IsDeleted() || f.IsDirectory() { return 128 } if f.NumBlocks < 2 { @@ -86,17 +90,27 @@ func (f FileInfoTruncated) Size() int64 { } func (f FileInfoTruncated) IsDeleted() bool { - return IsDeleted(f.Flags) + return f.Flags&FlagDeleted != 0 } func (f FileInfoTruncated) IsInvalid() bool { - return IsInvalid(f.Flags) + return f.Flags&FlagInvalid != 0 +} + +func (f FileInfoTruncated) IsDirectory() bool { + return f.Flags&FlagDirectory != 0 +} + +func (f FileInfoTruncated) HasPermissionBits() bool { + return f.Flags&FlagNoPermBits == 0 } type FileIntf interface { Size() int64 IsDeleted() bool IsInvalid() bool + IsDirectory() bool + HasPermissionBits() bool } type BlockInfo struct { diff --git a/internal/protocol/protocol.go b/internal/protocol/protocol.go index ae7f480b..7de53eab 100644 --- a/internal/protocol/protocol.go +++ b/internal/protocol/protocol.go @@ -637,19 +637,3 @@ func (c *rawConnection) Statistics() Statistics { OutBytesTotal: c.cw.Tot(), } } - -func IsDeleted(bits uint32) bool { - return bits&FlagDeleted != 0 -} - -func IsInvalid(bits uint32) bool { - return bits&FlagInvalid != 0 -} - -func IsDirectory(bits uint32) bool { - return bits&FlagDirectory != 0 -} - -func HasPermissionBits(bits uint32) bool { - return bits&FlagNoPermBits == 0 -} diff --git a/internal/scanner/blockqueue.go b/internal/scanner/blockqueue.go index 9d75dac7..cd0a0a11 100644 --- a/internal/scanner/blockqueue.go +++ b/internal/scanner/blockqueue.go @@ -68,7 +68,7 @@ func HashFile(path string, blockSize int) ([]protocol.BlockInfo, error) { func hashFiles(dir string, blockSize int, outbox, inbox chan protocol.FileInfo) { for f := range inbox { - if protocol.IsDirectory(f.Flags) || protocol.IsDeleted(f.Flags) { + if f.IsDirectory() || f.IsDeleted() { outbox <- f continue } diff --git a/internal/scanner/walk.go b/internal/scanner/walk.go index 927a41e8..bd3ecc4f 100644 --- a/internal/scanner/walk.go +++ b/internal/scanner/walk.go @@ -134,8 +134,8 @@ func (w *Walker) walkAndHashFiles(fchan chan protocol.FileInfo) filepath.WalkFun if info.Mode().IsDir() { if w.CurrentFiler != nil { cf := w.CurrentFiler.CurrentFile(rn) - permUnchanged := w.IgnorePerms || !protocol.HasPermissionBits(cf.Flags) || PermsEqual(cf.Flags, uint32(info.Mode())) - if !protocol.IsDeleted(cf.Flags) && protocol.IsDirectory(cf.Flags) && permUnchanged { + permUnchanged := w.IgnorePerms || !cf.HasPermissionBits() || PermsEqual(cf.Flags, uint32(info.Mode())) + if !cf.IsDeleted() && cf.IsDirectory() && permUnchanged { return nil } } @@ -162,8 +162,8 @@ func (w *Walker) walkAndHashFiles(fchan chan protocol.FileInfo) filepath.WalkFun if info.Mode().IsRegular() { if w.CurrentFiler != nil { cf := w.CurrentFiler.CurrentFile(rn) - permUnchanged := w.IgnorePerms || !protocol.HasPermissionBits(cf.Flags) || PermsEqual(cf.Flags, uint32(info.Mode())) - if !protocol.IsDeleted(cf.Flags) && cf.Modified == info.ModTime().Unix() && permUnchanged { + permUnchanged := w.IgnorePerms || !cf.HasPermissionBits() || PermsEqual(cf.Flags, uint32(info.Mode())) + if !cf.IsDeleted() && cf.Modified == info.ModTime().Unix() && permUnchanged { return nil }