diff --git a/internal/copier/copier.go b/internal/copier/copier.go index 8a3ad3d..b5d69a0 100644 --- a/internal/copier/copier.go +++ b/internal/copier/copier.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "math/rand/v2" "os" "os/exec" "path/filepath" @@ -134,6 +135,9 @@ func (c *Copier) run(ctx context.Context, taskID string, opts Options, database return } + // случайный порядок — выбираем что копировать до начала копирования + rand.Shuffle(len(files), func(i, j int) { files[i], files[j] = files[j], files[i] }) + _, free, err := disk.DiskUsage(opts.MountPath) if err != nil { fail(err) @@ -160,11 +164,12 @@ func (c *Copier) run(ctx context.Context, taskID string, opts Options, database } if f.size > available { + // файл не влезает — пробуем следующий continue } - msg := fmt.Sprintf("Копирование %s (%d/%d)", filepath.Base(f.srcAbs), i+1, total) prog := int(float64(i+1) / float64(total) * 100) + msg := fmt.Sprintf("Копирование %s (%d/%d)", filepath.Base(f.srcAbs), i+1, total) setStatus(task.StatusRunning, msg, prog) // destination mirrors source structure under destRoot