From 63452fe1ab51df44422e0237dbc933f0a669d0fc Mon Sep 17 00:00:00 2001 From: zerlei <1445089819@qq.com> Date: Mon, 9 Sep 2024 08:59:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8F=96=E6=B6=88=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 不是核心问题,文件权限失败时手动处理 --- Server/Common/Dir.cs | 163 ++++++++++++++++++++++--------------------- 1 file changed, 83 insertions(+), 80 deletions(-) diff --git a/Server/Common/Dir.cs b/Server/Common/Dir.cs index 7c577d1..5841708 100644 --- a/Server/Common/Dir.cs +++ b/Server/Common/Dir.cs @@ -363,6 +363,7 @@ public class Dir(string path, List? children = null, NextOpType? nex { static void f(Dir dir, FileDirOpStra fileDirOp) { + dir.AccessCheck(); foreach (var child in dir.Children) { if (child.Type == DirOrFile.Dir) @@ -394,86 +395,88 @@ public class Dir(string path, List? children = null, NextOpType? nex /// private void AccessCheck() { - this.Children.ForEach(e => - { - if (e is File file) - { - if (file.NextOp == null) { } - else if (file.NextOp == NextOpType.Add) - { - if ( - !AccessWrapper.CheckDirAccess( - Path.GetDirectoryName(file.FormatedPath) - ?? throw new DirectoryNotFoundException( - $"{file.FormatedPath} 此父路径不存在" - ), - [DirAcess.CreateFiles] - ) - ) - { - throw new UnauthorizedAccessException($"{file.FormatedPath} 无权限创建文件"); - } - } - else if (file.NextOp == NextOpType.Modify) - { - if ( - !( - AccessWrapper.CheckFileAccess(file.FormatedPath, [FileAccess.Delete]) - && AccessWrapper.CheckDirAccess( - Path.GetDirectoryName(file.FormatedPath) - ?? throw new DirectoryNotFoundException( - $"{file.FormatedPath} 此父路径不存在" - ), - [DirAcess.CreateFiles] - ) - ) - ) - { - throw new UnauthorizedAccessException( - $"{file.FormatedPath} 无权限删除源文件或者创建新文件" - ); - } - } - else if (file.NextOp == NextOpType.Del) - { - if (!AccessWrapper.CheckFileAccess(file.FormatedPath, [FileAccess.Delete])) - { - throw new UnauthorizedAccessException($"{file.FormatedPath} 无权限删除源文件"); - } - } - } - else if (e is Dir dir) - { - if (dir.NextOp == null) { } - else if (dir.NextOp == NextOpType.Add) - { - if ( - !AccessWrapper.CheckDirAccess( - Path.GetDirectoryName(dir.FormatedPath) - ?? throw new DirectoryNotFoundException( - $"{dir.FormatedPath} 此父路径不存在" - ), - [DirAcess.CreateDirectories, DirAcess.CreateFiles] - ) - ) - { - throw new UnauthorizedAccessException($"{dir.FormatedPath} 无权限创建文件夹或者文件"); - } - } - else if (dir.NextOp == NextOpType.Del) - { - if (!AccessWrapper.CheckDirAccess(dir.FormatedPath, [DirAcess.Delete])) - { - throw new UnauthorizedAccessException($"{dir.FormatedPath} 无权限删除文件夹"); - } - else - { - //校验是否拥有子文件或者文件夹的删除权限, - dir.AccessCheck(); - } - } - } - }); + //不是核心关注点,下面实现有bug。不校验所有文件夹权限,创建时会抛出错误,此时手动处理吧。 + return; + //this.Children.ForEach(e => + //{ + // if (e is File file) + // { + // if (file.NextOp == null) { } + // else if (file.NextOp == NextOpType.Add) + // { + // if ( + // !AccessWrapper.CheckDirAccess( + // Path.GetDirectoryName(file.FormatedPath) + // ?? throw new DirectoryNotFoundException( + // $"{file.FormatedPath} 此父路径不存在" + // ), + // [DirAcess.CreateFiles] + // ) + // ) + // { + // throw new UnauthorizedAccessException($"{file.FormatedPath} 无权限创建文件"); + // } + // } + // else if (file.NextOp == NextOpType.Modify) + // { + // if ( + // !( + // AccessWrapper.CheckFileAccess(file.FormatedPath, [FileAccess.Delete]) + // && AccessWrapper.CheckDirAccess( + // Path.GetDirectoryName(file.FormatedPath) + // ?? throw new DirectoryNotFoundException( + // $"{file.FormatedPath} 此父路径不存在" + // ), + // [DirAcess.CreateFiles] + // ) + // ) + // ) + // { + // throw new UnauthorizedAccessException( + // $"{file.FormatedPath} 无权限删除源文件或者创建新文件" + // ); + // } + // } + // else if (file.NextOp == NextOpType.Del) + // { + // if (!AccessWrapper.CheckFileAccess(file.FormatedPath, [FileAccess.Delete])) + // { + // throw new UnauthorizedAccessException($"{file.FormatedPath} 无权限删除源文件"); + // } + // } + // } + // else if (e is Dir dir) + // { + // if (dir.NextOp == null) { } + // else if (dir.NextOp == NextOpType.Add) + // { + // if ( + // !AccessWrapper.CheckDirAccess( + // Path.GetDirectoryName(dir.FormatedPath) + // ?? throw new DirectoryNotFoundException( + // $"{dir.FormatedPath} 此父路径不存在" + // ), + // [DirAcess.CreateDirectories, DirAcess.CreateFiles] + // ) + // ) + // { + // throw new UnauthorizedAccessException($"{dir.FormatedPath} 无权限创建文件夹或者文件"); + // } + // } + // else if (dir.NextOp == NextOpType.Del) + // { + // if (!AccessWrapper.CheckDirAccess(dir.FormatedPath, [DirAcess.Delete])) + // { + // throw new UnauthorizedAccessException($"{dir.FormatedPath} 无权限删除文件夹"); + // } + // else + // { + // //校验是否拥有子文件或者文件夹的删除权限, + // dir.AccessCheck(); + // } + // } + // } + //}); } ///