From 925df9c7e2c48e589ef62e38ae3cd3a3d3457ef3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=9F=B3=E5=A4=B4?= Date: Fri, 18 Oct 2024 15:32:51 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=B3=E8=BD=AC=E9=93=BE=E6=8E=A5=EF=BC=8C?= =?UTF-8?q?=E5=A4=9A=E4=B8=AA=E6=96=87=E4=BB=B6=E7=AC=A6=E5=90=88=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E5=8F=96=E5=90=8D=E5=AD=97=E8=BE=83=E7=9F=AD=E8=80=85?= =?UTF-8?q?=EF=BC=8C=E8=BF=87=E6=BB=A4=E6=8E=89=20-composite-?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EasyWeb/Services/EntryService.cs | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/EasyWeb/Services/EntryService.cs b/EasyWeb/Services/EntryService.cs index 82fc196..afdf7a3 100644 --- a/EasyWeb/Services/EntryService.cs +++ b/EasyWeb/Services/EntryService.cs @@ -282,6 +282,14 @@ public FileEntry GetLink(FileEntry entry) } private FileEntry MatchLink(Int32 storageId, Int32 parentId, String[] matchs) + { + return MatchLinks(storageId, parentId, matchs) + .OrderByDescending(e => e.Version) + .ThenBy(e => e.Name.Length) + .FirstOrDefault(); + } + + private IList MatchLinks(Int32 storageId, Int32 parentId, String[] matchs) { var m = matchs[0]; var flag = true; @@ -301,7 +309,7 @@ private FileEntry MatchLink(Int32 storageId, Int32 parentId, String[] matchs) else childs = childs.Where(e => !e.IsDirectory && !m.IsMatch(e.Name)).ToList(); - return childs.OrderByDescending(e => e.LastWrite).FirstOrDefault(); + return childs; } else { @@ -312,17 +320,21 @@ private FileEntry MatchLink(Int32 storageId, Int32 parentId, String[] matchs) if (childs.Count == 0) return null; // 递归查找子目录,找到最新的文件 - FileEntry fe = null; + var links = new List(); foreach (var item in childs) { - var rs = MatchLink(storageId, item.Id, matchs[1..]); - if (rs != null && (fe == null || rs.Version > fe.Version)) - { - fe = rs; - } + var rs = MatchLinks(storageId, item.Id, matchs[1..]); + if (rs != null) links.AddRange(rs); } - return fe; + //var fe = links.OrderByDescending(e => e.Version).FirstOrDefault(); + //return fe; + if (links.Count > 0) + { + var max = links.Max(e => e.Version); + links = links.Where(e => e.Version == max).ToList(); + } + return links; } }