checkFileInfoConsistency verifies a number of invariants on the given FileInfo
(f FileInfo)
| 620 | |
| 621 | // checkFileInfoConsistency verifies a number of invariants on the given FileInfo |
| 622 | func 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 |