chore(model): refactor copier for more flatness (#10094)

Flattened the copier code more. Also removing and moving some
parameters/return values to simplify things. Generally rely less on
return values, e.g. by handling errors right away and using `state` to
do the right thing (e.g. abort on failure).

Supposed to be a refactor without any behaviour changes, except for
fixing a tiny regression on folder order: We used to try copying from
the same folder first, but lost that property at some point (also sent a
PR fixing only that, I'd merge that first making this refactor only).
This commit is contained in:
Simon Frei
2025-05-04 09:23:57 +02:00
committed by GitHub
parent fa7b81e1cf
commit 821d6f43ac
2 changed files with 106 additions and 67 deletions
+12
View File
@@ -14,6 +14,7 @@ import (
"io"
"os"
"path/filepath"
"runtime/pprof"
"strconv"
"strings"
"testing"
@@ -680,6 +681,17 @@ func TestCopyOwner(t *testing.T) {
expGroup = 5678
)
// This test hung on a regression, taking a long time to fail - speed that up.
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
go func() {
<-ctx.Done()
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
pprof.Lookup("goroutine").WriteTo(os.Stdout, 2)
panic("timed out before test finished")
}
}()
// Set up a folder with the CopyParentOwner bit and backed by a fake
// filesystem.