From 638e9acf89a81a2fb3d9473623bd46e2b52f3aa0 Mon Sep 17 00:00:00 2001 From: gaohuatao Date: Thu, 6 Jun 2024 11:50:59 +0800 Subject: [PATCH] runtime: fix the bug of func countFiles When the total number of files observed is greater than limit, return (-1, err). When the returned err is not nil, the func countFiles should return -1. Fixes:#9780 Signed-off-by: gaohuatao --- src/runtime/virtcontainers/mount.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/runtime/virtcontainers/mount.go b/src/runtime/virtcontainers/mount.go index 40fbae2a92..e9f44dffd7 100644 --- a/src/runtime/virtcontainers/mount.go +++ b/src/runtime/virtcontainers/mount.go @@ -388,7 +388,11 @@ func countFiles(path string, limit int) (numFiles int, err error) { if file.IsDir() { inc, err := countFiles(filepath.Join(path, file.Name()), (limit - numFiles)) if err != nil { - return numFiles, err + return 0, err + } + // exceeded limit + if inc == -1 { + return -1, nil } numFiles = numFiles + inc } else {