From 91dfecf8828fb0c9e7c2eacefe496e276c41ddbc Mon Sep 17 00:00:00 2001 From: dami Date: Tue, 7 Jul 2026 23:36:34 +0800 Subject: [PATCH] up --- plugins/webstats/tool_migrate.py | 4 ++-- web/core/mw.py | 20 +++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/plugins/webstats/tool_migrate.py b/plugins/webstats/tool_migrate.py index 50a626fe0..7423652e3 100644 --- a/plugins/webstats/tool_migrate.py +++ b/plugins/webstats/tool_migrate.py @@ -116,9 +116,9 @@ def migrateSiteHotLogs(site_name, query_date): time.sleep(0.5) copy_start = time.time() # import shutil - # shutil.copy(hot_db, hot_db_tmp) + shutil.copy(hot_db, hot_db_tmp) # mw.fastCopy(hot_db, hot_db_tmp, 256 * 1024) - mw.sendfile(hot_db,hot_db_tmp) + # mw.sendfile(hot_db,hot_db_tmp) print(f"[{site_name}] 备份完成,耗时 {time.time() - copy_start:.2f}s") if not os.path.exists(hot_db_tmp): return mw.returnMsg(False, f"{site_name} migrating fail, copy tmp file!") diff --git a/web/core/mw.py b/web/core/mw.py index 3674502e0..2225b286f 100644 --- a/web/core/mw.py +++ b/web/core/mw.py @@ -327,15 +327,25 @@ def fastCopy(src, dst, buffer_size=256 * 1024): # 128MB 缓冲区 # linux高效复制 def sendfile(src, dst): if isAppleSystem(): - shutil.copyfile(src, dst) - return True + try: + shutil.copyfile(src, dst) + return True + except Exception as e: + return False + try: with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst: filesize = os.fstat(fsrc.fileno()).st_size - os.sendfile(fdst.fileno(), fsrc.fileno(), 0, filesize) + sent = os.sendfile(fdst.fileno(), fsrc.fileno(), 0, filesize) + if sent != filesize: + shutil.copyfile(src, dst) return True - except OSError as e: - return False + except (OSError, AttributeError) as e: + try: + shutil.copyfile(src, dst) + return True + except Exception as e2: + return False def returnData(status, msg, data=None): if data is None: