MCPcopy
hub / github.com/syncthing/syncthing / checkFileInfoConsistency

Function checkFileInfoConsistency

lib/protocol/protocol.go:622–641  ·  view source on GitHub ↗

checkFileInfoConsistency verifies a number of invariants on the given FileInfo

(f FileInfo)

Source from the content-addressed store, hash-verified

620
621// checkFileInfoConsistency verifies a number of invariants on the given FileInfo
622func checkFileInfoConsistency(f FileInfo) error {
623 if err := checkFilename(f.Name); err != nil {
624 return err
625 }
626
627 switch {
628 case f.Deleted && len(f.Blocks) != 0:
629 // Deleted files should have no blocks
630 return errDeletedHasBlocks
631
632 case f.Type == FileInfoTypeDirectory && len(f.Blocks) != 0:
633 // Directories should have no blocks
634 return errDirectoryHasBlocks
635
636 case !f.Deleted && !f.IsInvalid() && f.Type == FileInfoTypeFile && len(f.Blocks) == 0:
637 // Non-deleted, non-invalid files should have at least one block
638 return errFileHasNoBlocks
639 }
640 return nil
641}
642
643// checkFilename verifies that the given filename is valid according to the
644// spec on what's allowed over the wire. A filename failing this test is

Callers 3

TestCheckConsistencyFunction · 0.85
checkIndexConsistencyFunction · 0.85

Calls 2

checkFilenameFunction · 0.85
IsInvalidMethod · 0.45

Tested by 2

TestCheckConsistencyFunction · 0.68