From e1f199c98624fe3f5cdc83307d092dfb3b10335e Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sat, 2 Dec 2023 15:22:16 +0800 Subject: [PATCH] =?UTF-8?q?deleteRecordDirectory=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=BF=BD=E7=95=A5=E6=AD=A3=E5=9C=A8=E5=BD=95=E5=88=B6=E7=9A=84?= =?UTF-8?q?mp4=E6=96=87=E4=BB=B6=20(#3032)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/WebApi.cpp | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/server/WebApi.cpp b/server/WebApi.cpp index d71cbec0..2dec2d22 100755 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -1536,13 +1536,29 @@ void installWebApi() { if (!name.empty()) { record_path += name; } - int result = File::delete_file(record_path.data()); - if (result) { - // 不等于0时代表失败 - record_path = "delete error"; + bool recording = false; + { + auto src = MediaSource::find(allArgs["vhost"], allArgs["app"], allArgs["stream"]); + if (src && src->isRecording(Recorder::type_mp4)) { + recording = true; + } } val["path"] = record_path; - val["code"] = result; + if (!recording) { + val["code"] = File::delete_file(record_path.data()); + return; + } + File::scanDir(record_path, [](const string &path, bool is_dir) { + if (is_dir) { + return true; + } + if (path.find("./") != std::string::npos) { + File::delete_file(path.data()); + } else { + TraceL << "Ignore tmp mp4 file: " << path; + } + return true; + }, true); }); //获取录像文件夹列表或mp4文件列表