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

This commit is contained in:
Simon Frei 2020-02-19 16:58:09 +01:00 committed by Jakob Borg
parent bb375b1aff
commit a4bd4d118a
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 {
return protocol.FileInfo{
Name: f.Name,
Type: f.Type,
ModifiedS: f.ModifiedS,
ModifiedNs: f.ModifiedNs,
ModifiedBy: by,
Version: f.Version,
RawBlockSize: f.RawBlockSize,
LocalFlags: protocol.FlagLocalIgnored,
}
file := f.copyToFileInfo()
file.SetIgnored(by)
return file
}
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{
Name: f.Name,
Type: f.Type,
ModifiedS: time.Now().Unix(),
ModifiedBy: by,
Deleted: true,
Version: f.Version.Update(by),
LocalFlags: localFlags,
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,
Permissions: f.Permissions,
ModifiedNs: f.ModifiedNs,
RawBlockSize: f.RawBlockSize,
LocalFlags: f.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 {
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

View File

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

View File

@ -104,14 +104,8 @@ func (f *receiveOnlyFolder) Revert() {
return true // continue
}
fi = protocol.FileInfo{
Name: fi.Name,
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
}
fi.SetDeleted(f.shortID)
fi.Version = protocol.Vector{} // if this file ever resurfaces anywhere we want our delete to be strictly older
} else {
// Revert means to throw away our local changes. We reset the
// 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 {
// We are missing the file
need.Deleted = true
need.Blocks = nil
need.Version = need.Version.Update(f.shortID)
need.Size = 0
need.SetDeleted(f.shortID)
} else {
// We have the file, replace with our version
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) {
f.LocalFlags = FlagLocalMustRescan
f.ModifiedBy = by
f.Blocks = nil
f.Sequence = 0
f.setLocalFlags(by, FlagLocalMustRescan)
}
func (f *FileInfo) SetIgnored(by ShortID) {
f.LocalFlags = FlagLocalIgnored
f.ModifiedBy = by
f.Blocks = nil
f.Sequence = 0
f.setLocalFlags(by, FlagLocalIgnored)
}
func (f *FileInfo) SetUnsupported(by ShortID) {
f.LocalFlags = FlagLocalUnsupported
f.setLocalFlags(by, FlagLocalUnsupported)
}
func (f *FileInfo) SetDeleted(by ShortID) {
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.Sequence = 0
f.BlocksHash = nil
f.Size = 0
}
func (b BlockInfo) String() string {