From b373d653ca50c186a85583108fad2c9e9fd5ed7a Mon Sep 17 00:00:00 2001 From: tp1415926535 Date: Thu, 4 Jan 2024 05:54:55 +0000 Subject: [PATCH] =?UTF-8?q?=E5=B7=AE=E5=88=86=E5=88=A4=E6=96=AD=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6=E4=BD=BF=E7=94=A8=E2=80=9C=E7=9B=B8=E5=AF=B9=E4=BA=8E?= =?UTF-8?q?=E6=A0=B9=E7=9B=AE=E5=BD=95=E7=9A=84=E8=B7=AF=E5=BE=84=E2=80=9D?= =?UTF-8?q?=E8=80=8C=E4=B8=8D=E6=98=AF=E6=96=87=E4=BB=B6=E5=90=8D=EF=BC=8C?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E5=9B=A0=E4=B8=BA=E4=B8=8D=E5=90=8C=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=B9=E5=86=85=E7=9A=84=E5=AD=98=E5=9C=A8=E5=90=8C?= =?UTF-8?q?=E5=90=8D=E6=96=87=E4=BB=B6=E5=AF=BC=E8=87=B4=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: tp1415926535 --- .../ContentProvider/FileNode.cs | 4 +++- .../ContentProvider/FileProvider.cs | 17 +++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/c#/GeneralUpdate.Differential/ContentProvider/FileNode.cs b/src/c#/GeneralUpdate.Differential/ContentProvider/FileNode.cs index 43f266e..bb0851f 100644 --- a/src/c#/GeneralUpdate.Differential/ContentProvider/FileNode.cs +++ b/src/c#/GeneralUpdate.Differential/ContentProvider/FileNode.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace GeneralUpdate.Differential.ContentProvider { @@ -24,6 +24,8 @@ namespace GeneralUpdate.Differential.ContentProvider public int RightType { get; set; } + public string RelativePath { get; set; } + #endregion Public Properties #region Constructors diff --git a/src/c#/GeneralUpdate.Differential/ContentProvider/FileProvider.cs b/src/c#/GeneralUpdate.Differential/ContentProvider/FileProvider.cs index bf15a96..f8a6f8f 100644 --- a/src/c#/GeneralUpdate.Differential/ContentProvider/FileProvider.cs +++ b/src/c#/GeneralUpdate.Differential/ContentProvider/FileProvider.cs @@ -1,4 +1,4 @@ -using GeneralUpdate.Core.HashAlgorithms; +using GeneralUpdate.Core.HashAlgorithms; using GeneralUpdate.Differential.Common; using System; using System.Collections.Generic; @@ -48,8 +48,8 @@ namespace GeneralUpdate.Differential.ContentProvider { var leftFileNodes = Read(leftPath); var rightFileNodes = Read(rightPath); - var rightNodeDic = rightFileNodes.ToDictionary(x => x.Name, x => x); - var filesOnlyInLeft = leftFileNodes.Where(f => !rightNodeDic.ContainsKey(f.Name)).ToList(); + var rightNodeDic = rightFileNodes.ToDictionary(x => x.RelativePath, x => x); + var filesOnlyInLeft = leftFileNodes.Where(f => !rightNodeDic.ContainsKey(f.RelativePath)).ToList(); return filesOnlyInLeft; }); } @@ -62,10 +62,14 @@ namespace GeneralUpdate.Differential.ContentProvider /// Recursively read all files in the folder path. /// /// folder path. + /// folder root path. /// different chalders. - private IEnumerable Read(string path) + private IEnumerable Read(string path, string rootPath = null) { var resultFiles = new List(); + if (string.IsNullOrEmpty(rootPath)) rootPath = path; + if (!rootPath.EndsWith("/")) rootPath += "/"; + Uri rootUri = new Uri(rootPath); foreach (var subPath in Directory.GetFiles(path)) { if (IsMatchBlacklist(subPath)) continue; @@ -73,11 +77,12 @@ namespace GeneralUpdate.Differential.ContentProvider var hashAlgorithm = new Sha256HashAlgorithm(); var hash = hashAlgorithm.ComputeHash(subPath); var subFileInfo = new FileInfo(subPath); - resultFiles.Add(new FileNode() { Id = GetId(), Path = path, Name = subFileInfo.Name, Hash = hash, FullName = subFileInfo.FullName }); + Uri subUri = new Uri(subFileInfo.FullName); + resultFiles.Add(new FileNode() { Id = GetId(), Path = path, Name = subFileInfo.Name, Hash = hash, FullName = subFileInfo.FullName, RelativePath = rootUri.MakeRelativeUri(subUri).ToString() }); } foreach (var subPath in Directory.GetDirectories(path)) { - resultFiles.AddRange(Read(subPath)); + resultFiles.AddRange(Read(subPath, rootPath)); } return resultFiles; } -- Gitee