From c87a489514f5d20909d99ae666e48ccde0f3f812 Mon Sep 17 00:00:00 2001 From: jiuker <2818723467@qq.com> Date: Mon, 29 Jul 2024 15:59:50 +0800 Subject: [PATCH] fix: support prefix when batchJob replicate enable the snowball (#20178) --- cmd/batch-handlers.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd/batch-handlers.go b/cmd/batch-handlers.go index a12b36219..a313784a2 100644 --- a/cmd/batch-handlers.go +++ b/cmd/batch-handlers.go @@ -540,7 +540,7 @@ func toObjectInfo(bucket, object string, objInfo miniogo.ObjectInfo) ObjectInfo return oi } -func (r BatchJobReplicateV1) writeAsArchive(ctx context.Context, objAPI ObjectLayer, remoteClnt *minio.Client, entries []ObjectInfo) error { +func (r BatchJobReplicateV1) writeAsArchive(ctx context.Context, objAPI ObjectLayer, remoteClnt *minio.Client, entries []ObjectInfo, prefix string) error { input := make(chan minio.SnowballObject, 1) opts := minio.SnowballOptions{ Opts: minio.PutObjectOptions{}, @@ -562,6 +562,10 @@ func (r BatchJobReplicateV1) writeAsArchive(ctx context.Context, objAPI ObjectLa continue } + if prefix != "" { + entry.Name = pathJoin(prefix, entry.Name) + } + snowballObj := minio.SnowballObject{ // Create path to store objects within the bucket. Key: entry.Name, @@ -1135,7 +1139,7 @@ func (r *BatchJobReplicateV1) Start(ctx context.Context, api ObjectLayer, job Ba batch := make([]ObjectInfo, 0, *r.Source.Snowball.Batch) writeFn := func(batch []ObjectInfo) { if len(batch) > 0 { - if err := r.writeAsArchive(ctx, api, cl, batch); err != nil { + if err := r.writeAsArchive(ctx, api, cl, batch, r.Target.Prefix); err != nil { batchLogOnceIf(ctx, err, job.ID+"writeAsArchive") for _, b := range batch { slowCh <- itemOrErr[ObjectInfo]{Item: b}