Skip to content

Commit

Permalink
Merge pull request #41 from walterlv/t/lindexi/PackageDirectory
Browse files Browse the repository at this point in the history
删除文件夹时判断系统以及防止多次删除
  • Loading branch information
walterlv authored Apr 24, 2024
2 parents 4dff399 + 9554017 commit 610b165
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/Utils/Walterlv.IO.PackageManagement/PackageDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,7 @@ public static IOResult Delete(DirectoryInfo directory)
var logger = new IOResult();
logger.Log($"删除目录“{directory.FullName}”。");

if (JunctionPoint.Exists(directory.FullName))
{
JunctionPoint.Delete(directory.FullName);
}
else if (!Directory.Exists(directory.FullName))
if (!Directory.Exists(directory.FullName))
{
logger.Log($"要删除的目录“{directory.FullName}”不存在。");
return logger;
Expand All @@ -371,14 +367,22 @@ public static IOResult Delete(DirectoryInfo directory)

static void Delete(DirectoryInfo directory, int depth, IOResult logger)
{
if (JunctionPoint.Exists(directory.FullName))
if
(
#if NET6_0_OR_GREATER
OperatingSystem.IsWindows() &&
#endif
JunctionPoint.Exists(directory.FullName)
)
{
JunctionPoint.Delete(directory.FullName);
return;
}
#if NET6_0_OR_GREATER
else if(directory.LinkTarget != null)
{
directory.Delete();
return;
}
#endif
else if (!Directory.Exists(directory.FullName))
Expand All @@ -395,7 +399,7 @@ static void Delete(DirectoryInfo directory, int depth, IOResult logger)

foreach (var directoryInfo in directory.EnumerateDirectories("*", SearchOption.TopDirectoryOnly))
{
var back = string.Join("\\", Enumerable.Repeat("..", depth));
//var back = string.Join("\\", Enumerable.Repeat("..", depth));
Delete(directoryInfo, depth + 1, logger);
}

Expand Down

0 comments on commit 610b165

Please sign in to comment.