fix(protocol): be more stringent about blocks in non-file entries (#10737)

Directories, but also symlinks, should not have blocks or a size.

Signed-off-by: Jakob Borg <jakob@kastelo.net>
This commit is contained in:
Jakob Borg
2026-06-11 18:52:24 +02:00
committed by GitHub
parent f6428af4c8
commit 6606e6b4d3
+9 -4
View File
@@ -75,7 +75,8 @@ var (
errInvalidFilename = errors.New("filename is invalid") errInvalidFilename = errors.New("filename is invalid")
errUncleanFilename = errors.New("filename not in canonical format") errUncleanFilename = errors.New("filename not in canonical format")
errDeletedHasBlocks = errors.New("deleted file with non-empty block list") errDeletedHasBlocks = errors.New("deleted file with non-empty block list")
errDirectoryHasBlocks = errors.New("directory with non-empty block list") errNonFileHasBlocks = errors.New("non-file type with non-empty block list")
errNonFileHasSize = errors.New("non-file type with nonzero size")
errFileHasNoBlocks = errors.New("file with empty block list") errFileHasNoBlocks = errors.New("file with empty block list")
) )
@@ -635,9 +636,13 @@ func checkFileInfoConsistency(f FileInfo) error {
// Deleted files should have no blocks // Deleted files should have no blocks
return errDeletedHasBlocks return errDeletedHasBlocks
case f.Type == FileInfoTypeDirectory && len(f.Blocks) != 0: case f.Type != FileInfoTypeFile && len(f.Blocks) != 0:
// Directories should have no blocks // Only files should have blocks
return errDirectoryHasBlocks return errNonFileHasBlocks
case f.Type != FileInfoTypeFile && f.Size != 0:
// Only files should have a size
return errNonFileHasSize
case !f.Deleted && !f.IsInvalid() && f.Type == FileInfoTypeFile && len(f.Blocks) == 0: case !f.Deleted && !f.IsInvalid() && f.Type == FileInfoTypeFile && len(f.Blocks) == 0:
// Non-deleted, non-invalid files should have at least one block // Non-deleted, non-invalid files should have at least one block