lib/model: Fix file size inconsistency due to enc. trailer (#8840)
lib/model: Fix file size inconsisency due to enc. trailer Fixes a regression due to PR #8563, while arguable the bug was actually introduced in a much older PR #7155, but didn't have any bad effects so far: We account for the encryption trailer in the db updater routine, calculating the file-info size there. However there's no guarantee that the file-info at this point is still the exact same as when it was written. It was before, but isn't anymore since introducing the new EncryptedTrailerSize field. Fix: Adjust the size in the info at the same place where the trailer is written, i.e. we definitely have the actual size on disk.
This commit is contained in:
parent
51e85d5162
commit
6a66aee489
|
@ -1251,11 +1251,12 @@ func (f *sendReceiveFolder) shortcutFile(file protocol.FileInfo, dbUpdateChan ch
|
||||||
}
|
}
|
||||||
defer fd.Close()
|
defer fd.Close()
|
||||||
trailerSize, err := writeEncryptionTrailer(file, fd)
|
trailerSize, err := writeEncryptionTrailer(file, fd)
|
||||||
file.EncryptionTrailerSize = int(trailerSize)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return fd.Truncate(file.Size + trailerSize)
|
file.EncryptionTrailerSize = int(trailerSize)
|
||||||
|
file.Size += trailerSize
|
||||||
|
return fd.Truncate(file.Size)
|
||||||
}, f.mtimefs, file.Name, true)
|
}, f.mtimefs, file.Name, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
f.newPullError(file.Name, fmt.Errorf("writing encrypted file trailer: %w", err))
|
f.newPullError(file.Name, fmt.Errorf("writing encrypted file trailer: %w", err))
|
||||||
|
@ -1744,7 +1745,6 @@ func (f *sendReceiveFolder) dbUpdaterRoutine(dbUpdateChan <-chan dbUpdateJob) {
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
recvEnc := f.Type == config.FolderTypeReceiveEncrypted
|
|
||||||
loop:
|
loop:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
@ -1756,9 +1756,6 @@ loop:
|
||||||
switch job.jobType {
|
switch job.jobType {
|
||||||
case dbUpdateHandleFile, dbUpdateShortcutFile:
|
case dbUpdateHandleFile, dbUpdateShortcutFile:
|
||||||
changedDirs[filepath.Dir(job.file.Name)] = struct{}{}
|
changedDirs[filepath.Dir(job.file.Name)] = struct{}{}
|
||||||
if recvEnc {
|
|
||||||
job.file.Size += encryptionTrailerSize(job.file)
|
|
||||||
}
|
|
||||||
case dbUpdateHandleDir:
|
case dbUpdateHandleDir:
|
||||||
changedDirs[job.file.Name] = struct{}{}
|
changedDirs[job.file.Name] = struct{}{}
|
||||||
case dbUpdateHandleSymlink, dbUpdateInvalidate:
|
case dbUpdateHandleSymlink, dbUpdateInvalidate:
|
||||||
|
|
|
@ -352,9 +352,13 @@ func (s *sharedPullerState) finalizeEncrypted() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_, err := writeEncryptionTrailer(s.file, s.writer)
|
trailerSize, err := writeEncryptionTrailer(s.file, s.writer)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
s.file.Size += trailerSize
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Returns the size of the written trailer.
|
// Returns the size of the written trailer.
|
||||||
func writeEncryptionTrailer(file protocol.FileInfo, writer io.WriterAt) (int64, error) {
|
func writeEncryptionTrailer(file protocol.FileInfo, writer io.WriterAt) (int64, error) {
|
||||||
|
|
Loading…
Reference in New Issue