提交 2c3399d0 编写于 作者: J Jared Parsons 提交者: Jared Parsons

Cleanup storage

上级 11fde43e
......@@ -26,6 +26,7 @@ private enum StorageKind
Content
}
internal const int MaxStorageCount = 200;
internal const string DirectoryName = "RunTestsStorage";
private readonly string _storagePath;
......@@ -129,5 +130,32 @@ private string Read(string checksum, StorageKind kind)
var filePath = GetStoragePath(checksum, kind);
return File.ReadAllText(filePath);
}
private void CleanupStorage()
{
try
{
var files = Directory.GetFiles(_storagePath);
if (files.Length < MaxStorageCount)
{
return;
}
var clean = files.Length - (MaxStorageCount / 2);
var items = files
.Select(x => new DirectoryInfo(x))
.OrderBy(x => x.CreationTimeUtc)
.Take(clean);
foreach (var item in items)
{
FileUtil.DeleteDirectory(item.Name);
}
}
catch (Exception ex)
{
Console.WriteLine($"Unable to cleanup storage {ex.Message}");
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册