MCPcopy Index your code
hub / github.com/syncthing/syncthing / writeEncryptionTrailer

Function writeEncryptionTrailer

lib/model/sharedpullerstate.go:385–405  ·  view source on GitHub ↗

Returns the size of the written trailer.

(file protocol.FileInfo, writer io.WriterAt)

Source from the content-addressed store, hash-verified

383
384// Returns the size of the written trailer.
385func writeEncryptionTrailer(file protocol.FileInfo, writer io.WriterAt) (int64, error) {
386 // Here the file is in native format, while encryption happens in
387 // wire format (always slashes).
388 wireFile := file
389 wireFile.Name = osutil.NormalizedFilename(wireFile.Name)
390
391 trailerSize := encryptionTrailerSize(wireFile)
392 bs := make([]byte, trailerSize)
393 n, err := protoutil.MarshalTo(bs, wireFile.ToWire(false))
394 if err != nil {
395 return 0, err
396 }
397 binary.BigEndian.PutUint32(bs[n:], uint32(n)) //nolint:gosec
398 bs = bs[:n+4]
399
400 if _, err := writer.WriteAt(bs, wireFile.Size); err != nil {
401 return 0, err
402 }
403
404 return trailerSize, nil
405}
406
407func encryptionTrailerSize(file protocol.FileInfo) int64 {
408 return int64(proto.Size(file.ToWire(false))) + 4 // XXX: Inefficient

Callers 2

finalizeEncryptedMethod · 0.85
shortcutFileMethod · 0.85

Calls 5

NormalizedFilenameFunction · 0.92
MarshalToFunction · 0.92
encryptionTrailerSizeFunction · 0.85
ToWireMethod · 0.45
WriteAtMethod · 0.45

Tested by

no test coverage detected