lib: Modify FileInfos consistently (ref #6321) (#6349)

This commit is contained in:
Simon Frei 2020-02-19 16:58:09 +01:00 committed by GitHub
parent 7b5551248a
commit fae7425bbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 57 additions and 41 deletions

View File

@ -129,27 +129,36 @@ func (f FileInfoTruncated) FileModifiedBy() protocol.ShortID {
} }
func (f FileInfoTruncated) ConvertToIgnoredFileInfo(by protocol.ShortID) protocol.FileInfo { func (f FileInfoTruncated) ConvertToIgnoredFileInfo(by protocol.ShortID) protocol.FileInfo {
return protocol.FileInfo{ file := f.copyToFileInfo()
Name: f.Name, file.SetIgnored(by)
Type: f.Type, return file
ModifiedS: f.ModifiedS,
ModifiedNs: f.ModifiedNs,
ModifiedBy: by,
Version: f.Version,
RawBlockSize: f.RawBlockSize,
LocalFlags: protocol.FlagLocalIgnored,
}
} }
func (f FileInfoTruncated) ConvertToDeletedFileInfo(by protocol.ShortID, localFlags uint32) protocol.FileInfo { func (f FileInfoTruncated) ConvertToDeletedFileInfo(by protocol.ShortID) protocol.FileInfo {
file := f.copyToFileInfo()
file.SetDeleted(by)
return file
}
// copyToFileInfo just copies all members of FileInfoTruncated to protocol.FileInfo
func (f FileInfoTruncated) copyToFileInfo() protocol.FileInfo {
return protocol.FileInfo{ return protocol.FileInfo{
Name: f.Name, Name: f.Name,
Size: f.Size,
ModifiedS: f.ModifiedS,
ModifiedBy: f.ModifiedBy,
Version: f.Version,
Sequence: f.Sequence,
SymlinkTarget: f.SymlinkTarget,
BlocksHash: f.BlocksHash,
Type: f.Type, Type: f.Type,
ModifiedS: time.Now().Unix(), Permissions: f.Permissions,
ModifiedBy: by, ModifiedNs: f.ModifiedNs,
Deleted: true, RawBlockSize: f.RawBlockSize,
Version: f.Version.Update(by), LocalFlags: f.LocalFlags,
LocalFlags: localFlags, Deleted: f.Deleted,
RawInvalid: f.RawInvalid,
NoPermissions: f.NoPermissions,
} }
} }

View File

@ -468,6 +468,9 @@ func (t readWriteTransaction) putFile(key []byte, fi protocol.FileInfo) error {
} else if err != nil { } else if err != nil {
return err return err
} }
} else if fi.BlocksHash != nil {
l.Warnln("Blocks is nil, but BlocksHash is not for file", fi)
panic("Blocks is nil, but BlocksHash is not")
} }
fi.Blocks = nil fi.Blocks = nil

View File

@ -532,7 +532,8 @@ func (f *folder) scanSubdirs(subDirs []string) error {
} }
return true return true
} }
nf := file.ConvertToDeletedFileInfo(f.shortID, f.localFlags) nf := file.ConvertToDeletedFileInfo(f.shortID)
nf.LocalFlags = f.localFlags
if file.ShouldConflict() { if file.ShouldConflict() {
// We do not want to override the global version with // We do not want to override the global version with
// the deleted file. Setting to an empty version makes // the deleted file. Setting to an empty version makes

View File

@ -104,14 +104,8 @@ func (f *receiveOnlyFolder) Revert() {
return true // continue return true // continue
} }
fi = protocol.FileInfo{ fi.SetDeleted(f.shortID)
Name: fi.Name, fi.Version = protocol.Vector{} // if this file ever resurfaces anywhere we want our delete to be strictly older
Type: fi.Type,
ModifiedS: time.Now().Unix(),
ModifiedBy: f.shortID,
Deleted: true,
Version: protocol.Vector{}, // if this file ever resurfaces anywhere we want our delete to be strictly older
}
} else { } else {
// Revert means to throw away our local changes. We reset the // Revert means to throw away our local changes. We reset the
// version to the empty vector, which is strictly older than any // version to the empty vector, which is strictly older than any

View File

@ -118,10 +118,7 @@ func (f *sendOnlyFolder) Override() {
} }
if !ok || have.Name != need.Name { if !ok || have.Name != need.Name {
// We are missing the file // We are missing the file
need.Deleted = true need.SetDeleted(f.shortID)
need.Blocks = nil
need.Version = need.Version.Update(f.shortID)
need.Size = 0
} else { } else {
// We have the file, replace with our version // We have the file, replace with our version
have.Version = have.Version.Merge(need.Version).Update(f.shortID) have.Version = have.Version.Merge(need.Version).Update(f.shortID)

View File

@ -266,24 +266,36 @@ func BlocksEqual(a, b []BlockInfo) bool {
} }
func (f *FileInfo) SetMustRescan(by ShortID) { func (f *FileInfo) SetMustRescan(by ShortID) {
f.LocalFlags = FlagLocalMustRescan f.setLocalFlags(by, FlagLocalMustRescan)
f.ModifiedBy = by
f.Blocks = nil
f.Sequence = 0
} }
func (f *FileInfo) SetIgnored(by ShortID) { func (f *FileInfo) SetIgnored(by ShortID) {
f.LocalFlags = FlagLocalIgnored f.setLocalFlags(by, FlagLocalIgnored)
f.ModifiedBy = by
f.Blocks = nil
f.Sequence = 0
} }
func (f *FileInfo) SetUnsupported(by ShortID) { func (f *FileInfo) SetUnsupported(by ShortID) {
f.LocalFlags = FlagLocalUnsupported f.setLocalFlags(by, FlagLocalUnsupported)
}
func (f *FileInfo) SetDeleted(by ShortID) {
f.ModifiedBy = by f.ModifiedBy = by
f.Deleted = true
f.Version = f.Version.Update(by)
f.ModifiedS = time.Now().Unix()
f.setNoContent()
}
func (f *FileInfo) setLocalFlags(by ShortID, flags uint32) {
f.RawInvalid = false
f.LocalFlags = flags
f.ModifiedBy = by
f.setNoContent()
}
func (f *FileInfo) setNoContent() {
f.Blocks = nil f.Blocks = nil
f.Sequence = 0 f.BlocksHash = nil
f.Size = 0
} }
func (b BlockInfo) String() string { func (b BlockInfo) String() string {