From 66114a56de4ff8fdf8dfe6ebec4b7cd47ecfbdd1 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Mon, 8 Jul 2024 09:41:40 -0500 Subject: [PATCH] commentary --- staker/challenge-cache/cache.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/staker/challenge-cache/cache.go b/staker/challenge-cache/cache.go index f2f53738f7..720f71db44 100644 --- a/staker/challenge-cache/cache.go +++ b/staker/challenge-cache/cache.go @@ -201,7 +201,7 @@ func (c *Cache) Prune(ctx context.Context, messageNumber uint64) error { if err != nil { return err } - // Delete the directory if the message number is <= the specified value. + // Collect the directory path if the message number is <= the specified value. if dirNameMessageNum <= int(messageNumber) { pathsToDelete = append(pathsToDelete, path) } @@ -211,6 +211,8 @@ func (c *Cache) Prune(ctx context.Context, messageNumber uint64) error { }); err != nil { return err } + // We delete separately from collecting the paths, as deleting while walking + // a dir can cause issues with the filepath.Walk function. for _, path := range pathsToDelete { if err := os.RemoveAll(path); err != nil { return fmt.Errorf("could not prune directory with path %s: %w", path, err)