From 7e83591654cdafc64c8d69e44205797e2fabcb69 Mon Sep 17 00:00:00 2001 From: Andrea Bugeja Date: Thu, 4 Dec 2025 15:47:45 +0100 Subject: [PATCH] Add copy and move methods with required import --- rag/utils/minio_conn.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/rag/utils/minio_conn.py b/rag/utils/minio_conn.py index c18507470..42bb84250 100644 --- a/rag/utils/minio_conn.py +++ b/rag/utils/minio_conn.py @@ -17,6 +17,7 @@ import logging import time from minio import Minio +from minio.commonconfig import CopySource from minio.error import S3Error from io import BytesIO from common.decorator import singleton @@ -199,3 +200,37 @@ class RAGFlowMinio: self.conn.remove_bucket(bucket) except Exception: logging.exception(f"Fail to remove bucket {bucket}") + + def copy(self, src_bucket, src_path, dest_bucket, dest_path): + try: + if not self.conn.bucket_exists(dest_bucket): + self.conn.make_bucket(dest_bucket) + + try: + self.conn.stat_object(src_bucket, src_path) + except Exception as e: + logging.exception(f"Source object not found: {src_bucket}/{src_path}, {e}") + return False + + self.conn.copy_object( + dest_bucket, + dest_path, + CopySource(src_bucket, src_path), + ) + return True + + except Exception: + logging.exception(f"Fail to copy {src_bucket}/{src_path} -> {dest_bucket}/{dest_path}") + return False + + def move(self, src_bucket, src_path, dest_bucket, dest_path): + try: + if self.copy(src_bucket, src_path, dest_bucket, dest_path): + self.rm(src_bucket, src_path) + return True + else: + logging.error(f"Copy failed, move aborted: {src_bucket}/{src_path}") + return False + except Exception: + logging.exception(f"Fail to move {src_bucket}/{src_path} -> {dest_bucket}/{dest_path}") + return False