1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 03:52:19 +02:00

Added cleancache

This commit is contained in:
Brian Fiete 2024-10-25 17:20:00 -04:00
parent 31746c1f19
commit a1413866a7
3 changed files with 84 additions and 21 deletions

View file

@ -92,6 +92,14 @@ namespace BeefBuild
mWantsClean = false;
}
if (mVerb == .CleanCache)
{
LoadConfig();
mPackMan.CleanCache();
Stop();
return;
}
if (mWorkspace.mDir == null)
{
mWorkspace.mDir = new String();
@ -193,6 +201,10 @@ namespace BeefBuild
return true;
case "-crash":
Runtime.FatalError("-crash specified on command line");
case "-cleancache":
if (mPackMan.mCleanHashSet.TryAddAlt("*", var entryPtr))
*entryPtr = new .("*");
return true;
}
if (!key.StartsWith('-'))
@ -207,6 +219,8 @@ namespace BeefBuild
mVerb = .None;
case "new":
mVerb = .New;
case "cleancache":
mVerb = .CleanCache;
case "generate":
mWantsGenerate = true;
case "run":
@ -285,6 +299,10 @@ namespace BeefBuild
else
Fail(scope String()..AppendF("Invalid verbosity option: {}", value));
return true;
case "-cleancache":
if (mPackMan.mCleanHashSet.TryAddAlt(value, var entryPtr))
*entryPtr = new .(value);
return true;
}
}

View file

@ -77,7 +77,8 @@ namespace IDE
Test,
Run,
Update,
GetVersion
GetVersion,
CleanCache
}
enum HotResolveState
@ -13039,7 +13040,7 @@ namespace IDE
LoadConfig();
}
void LoadConfig()
protected void LoadConfig()
{
delete mBeefConfig;
mBeefConfig = new BeefConfig();

View file

@ -102,6 +102,15 @@ namespace IDE.util
outPath.AppendF($"{mManagedPath}/{hash}");
}
bool WantsHashClean(StringView hash)
{
if (mCleanHashSet.ContainsAlt(hash))
return true;
if (mCleanHashSet.Contains("*"))
return true;
return false;
}
public bool CheckLock(StringView projectName, String outPath, out bool failed)
{
failed = false;
@ -121,7 +130,7 @@ namespace IDE.util
switch (lock)
{
case .Git(let url, let tag, let hash):
if (mCleanHashSet.Contains(hash))
if (WantsHashClean(hash))
return false;
var path = GetPath(url, hash, .. scope .());
var managedFilePath = scope $"{path}/BeefManaged.toml";
@ -192,6 +201,35 @@ namespace IDE.util
});*/
}
public void DeleteDir(StringView path)
{
String tempDir;
if (path.Contains("__DELETE__"))
{
tempDir = new .(path);
}
else
{
tempDir = new $"{path}__DELETE__{(int32)Internal.GetTickCountMicro():X}";
if (Directory.Move(path, tempDir) case .Err)
{
delete tempDir;
Fail(scope $"Failed to remove directory '{path}'");
return;
}
}
ThreadPool.QueueUserWorkItem(new () =>
{
Directory.DelTree(tempDir);
}
~
{
delete tempDir;
});
}
public void GetWithHash(StringView projectName, StringView url, StringView tag, StringView hash)
{
if (!CheckInit())
@ -202,7 +240,7 @@ namespace IDE.util
Directory.CreateDirectory(urlPath).IgnoreError();
if (Directory.Exists(destPath))
{
if (!mCleanHashSet.ContainsAlt(hash))
if (!WantsHashClean(hash))
{
var managedFilePath = scope $"{destPath}/BeefManaged.toml";
if (File.Exists(managedFilePath))
@ -221,23 +259,7 @@ namespace IDE.util
}
}
String tempDir = new $"{destPath}__{(int32)Internal.GetTickCountMicro():X}";
if (Directory.Move(destPath, tempDir) case .Err)
{
delete tempDir;
Fail(scope $"Failed to remove directory '{destPath}'");
return;
}
ThreadPool.QueueUserWorkItem(new () =>
{
Directory.DelTree(tempDir);
}
~
{
delete tempDir;
});
DeleteDir(destPath);
}
if (gApp.mVerbosity >= .Normal)
@ -509,5 +531,27 @@ namespace IDE.util
Fail("Aborted project transfer");
mWorkItems.ClearAndDeleteItems();
}
public void CleanCache()
{
if (!CheckInit())
return;
if (mManagedPath.IsEmpty)
return;
for (var entry in Directory.EnumerateDirectories(mManagedPath))
{
if (!entry.IsDirectory)
continue;
var fileName = entry.GetFileName(.. scope .());
if (fileName.Length < 40)
continue;
var filePath = entry.GetFilePath(.. scope .());
DeleteDir(filePath);
}
}
}
}