From 308787072de23eb9e1815e70fce1f56d94cf4117 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 9 Dec 2024 23:44:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=A7=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=AE=A1=E7=AE=97hash=E6=8A=9B=E5=BC=82=E5=B8=B8=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Helpers/MasterHelper.cs | 13 +++++++------ src/Services/TaskManager.cs | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Helpers/MasterHelper.cs b/src/Helpers/MasterHelper.cs index b6c109a..10dd71d 100644 --- a/src/Helpers/MasterHelper.cs +++ b/src/Helpers/MasterHelper.cs @@ -133,14 +133,15 @@ namespace iFileProxy.Helpers byte[] hash = []; if (File.Exists(fileName)) { + using FileStream fileStream = File.OpenRead(fileName); hash = algorithm switch { - FileHashAlgorithm.MD5 => MD5.HashData(File.ReadAllBytes(fileName)), - FileHashAlgorithm.SHA1 => SHA1.HashData(File.ReadAllBytes(fileName)), - FileHashAlgorithm.SHA256 => SHA256.HashData(File.ReadAllBytes(fileName)), - FileHashAlgorithm.SHA384 => SHA384.HashData(File.ReadAllBytes(fileName)), - FileHashAlgorithm.SHA512 => SHA512.HashData(File.ReadAllBytes(fileName)), - _ => MD5.HashData(File.ReadAllBytes(fileName)), + FileHashAlgorithm.MD5 => MD5.HashData(fileStream), + FileHashAlgorithm.SHA1 => SHA1.HashData(fileStream), + FileHashAlgorithm.SHA256 => SHA256.HashData(fileStream), + FileHashAlgorithm.SHA384 => SHA384.HashData(fileStream), + FileHashAlgorithm.SHA512 => SHA512.HashData(fileStream), + _ => MD5.HashData(fileStream), }; StringBuilder sBuilder = new StringBuilder(); for (int i = 0; i < hash.Length; i++) diff --git a/src/Services/TaskManager.cs b/src/Services/TaskManager.cs index 496fd3d..f1d6b05 100644 --- a/src/Services/TaskManager.cs +++ b/src/Services/TaskManager.cs @@ -268,7 +268,7 @@ namespace iFileProxy.Services } catch (Exception ex) { - _logger.Fatal($"执行下载任务时候出现致命问题: {ex.Message}"); + _logger.Fatal("task: {taskid} 执行下载任务时候出现致命问题: {ex}",taskInfo.TaskId, ex); taskInfo.Status= TaskState.Error; _dbGateService.UpdateTaskStatus(taskInfo);