fix: Unexpected error during initial resource listing (#2579)

Signed-off-by: joyceliu <joyceliu@yunify.com>
This commit is contained in:
liujian 2025-05-20 10:45:07 +08:00 committed by GitHub
parent 6aec54a82f
commit ecfb0fe2b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -259,6 +259,14 @@ func (s fileStorage) getRootEntries(key string) ([]os.DirEntry, bool, error) {
default:
return nil, false, errors.Errorf("key is invalid: %s", key)
}
if _, err := os.Stat(key); err != nil {
if !os.IsNotExist(err) {
return nil, allNamespace, errors.Wrapf(err, "failed to stat path %q", key)
}
if err := os.MkdirAll(key, os.ModePerm); err != nil {
return nil, allNamespace, errors.Wrapf(err, "failed to create dir %q", key)
}
}
rootEntries, err := os.ReadDir(key)
return rootEntries, allNamespace, err