Skip to content

Commit

Permalink
星尘代理增加数据清理,用于删除历史错误数据
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Aug 29, 2024
1 parent 8d84c72 commit fe6f005
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions StarAgent/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ public override void StartWork(String reason)

if (_Client != null) _Client.Plugins = pm.Plugins.Select(e => e.GetType().Name.TrimEnd("Plugin")).ToArray();

// 辅助任务清理数据
ThreadPoolX.QueueUserWorkItem(Fix);

base.StartWork(reason);
}

Expand Down Expand Up @@ -631,4 +634,53 @@ Object IServiceProvider.GetService(Type serviceType)
return Provider?.GetService(serviceType);
}
#endregion

#region 辅助

/// <summary>清理历史版本文件</summary>
private void Fix()
{
foreach (var fi in "./".AsDirectory().GetFiles("*", SearchOption.TopDirectoryOnly))
{
var flag = false;
if (fi.Name.EndsWithIgnoreCase(".deps.json", ".runtimeconfig.json") && !fi.Name.StartsWithIgnoreCase("StarAgent"))
flag = true;
else if (fi.Name.EndsWithIgnoreCase(".tar.gz") && fi.LastAccessTime.AddMonths(1) < DateTime.Now)
flag = true;
else if (fi.Name.EndsWithIgnoreCase(".exe") && !Runtime.Windows && !Runtime.Mono)
flag = true;

if (flag)
{
try
{
_Client?.WriteInfoEvent("删除", fi.FullName);
XTrace.WriteLine("删除:{0}", fi.FullName);
fi.Delete();
}
catch (Exception ex)
{
_Client?.WriteErrorEvent("删除", ex.Message);
XTrace.Log.Error(ex.Message);
}
}
}

var di = "./runtimes".AsDirectory();
if (di.Exists)
{
try
{
_Client?.WriteInfoEvent("删除", di.FullName);
XTrace.WriteLine("删除:{0}", di.FullName);
di.Delete(true);
}
catch (Exception ex)
{
_Client?.WriteErrorEvent("删除", ex.Message);
XTrace.Log.Error(ex.Message);
}
}
}
#endregion
}

0 comments on commit fe6f005

Please sign in to comment.