also ignore errors from readdirnames (#15947)

* also ignore errors from readdirnames

* test case for empty blobs dir

---------

Co-authored-by: Kasey Kirkham <kasey@users.noreply.github.com>
This commit is contained in:
kasey
2025-10-30 14:02:25 -05:00
committed by GitHub
parent 5a1a5b5ae5
commit 3e0492a636
3 changed files with 14 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
### Ignored
- Fix bug with layout detection when readdirnames returns io.EOF.

View File

@@ -2,6 +2,7 @@ package storage
import (
"fmt"
"io"
"os"
"path"
"slices"
@@ -139,6 +140,10 @@ func detectLayout(dir string, c stringFlagGetter) (string, error) {
// amount of wiggle room to be confident that we'll likely see a by-root director if one exists.
entries, err := base.Readdirnames(16)
if err != nil {
// We can get this error if the directory exists and is empty
if errors.Is(err, io.EOF) {
return filesystem.LayoutNameByEpoch, nil
}
return "", errors.Wrap(err, "reading blob storage directory")
}
for _, entry := range entries {

View File

@@ -192,6 +192,13 @@ func TestDetectLayout(t *testing.T) {
},
expectedErr: syscall.ENOTDIR,
},
{
name: "empty blobs dir",
setup: func(t *testing.T, dir string) {
require.NoError(t, os.MkdirAll(dir, 0o755))
},
expected: filesystem.LayoutNameByEpoch,
},
}
for _, tc := range cases {