mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 03:52:19 +02:00
Added cleancache
This commit is contained in:
parent
31746c1f19
commit
a1413866a7
3 changed files with 84 additions and 21 deletions
|
@ -92,6 +92,14 @@ namespace BeefBuild
|
||||||
mWantsClean = false;
|
mWantsClean = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mVerb == .CleanCache)
|
||||||
|
{
|
||||||
|
LoadConfig();
|
||||||
|
mPackMan.CleanCache();
|
||||||
|
Stop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (mWorkspace.mDir == null)
|
if (mWorkspace.mDir == null)
|
||||||
{
|
{
|
||||||
mWorkspace.mDir = new String();
|
mWorkspace.mDir = new String();
|
||||||
|
@ -193,6 +201,10 @@ namespace BeefBuild
|
||||||
return true;
|
return true;
|
||||||
case "-crash":
|
case "-crash":
|
||||||
Runtime.FatalError("-crash specified on command line");
|
Runtime.FatalError("-crash specified on command line");
|
||||||
|
case "-cleancache":
|
||||||
|
if (mPackMan.mCleanHashSet.TryAddAlt("*", var entryPtr))
|
||||||
|
*entryPtr = new .("*");
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!key.StartsWith('-'))
|
if (!key.StartsWith('-'))
|
||||||
|
@ -207,6 +219,8 @@ namespace BeefBuild
|
||||||
mVerb = .None;
|
mVerb = .None;
|
||||||
case "new":
|
case "new":
|
||||||
mVerb = .New;
|
mVerb = .New;
|
||||||
|
case "cleancache":
|
||||||
|
mVerb = .CleanCache;
|
||||||
case "generate":
|
case "generate":
|
||||||
mWantsGenerate = true;
|
mWantsGenerate = true;
|
||||||
case "run":
|
case "run":
|
||||||
|
@ -285,6 +299,10 @@ namespace BeefBuild
|
||||||
else
|
else
|
||||||
Fail(scope String()..AppendF("Invalid verbosity option: {}", value));
|
Fail(scope String()..AppendF("Invalid verbosity option: {}", value));
|
||||||
return true;
|
return true;
|
||||||
|
case "-cleancache":
|
||||||
|
if (mPackMan.mCleanHashSet.TryAddAlt(value, var entryPtr))
|
||||||
|
*entryPtr = new .(value);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,8 @@ namespace IDE
|
||||||
Test,
|
Test,
|
||||||
Run,
|
Run,
|
||||||
Update,
|
Update,
|
||||||
GetVersion
|
GetVersion,
|
||||||
|
CleanCache
|
||||||
}
|
}
|
||||||
|
|
||||||
enum HotResolveState
|
enum HotResolveState
|
||||||
|
@ -13039,7 +13040,7 @@ namespace IDE
|
||||||
LoadConfig();
|
LoadConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadConfig()
|
protected void LoadConfig()
|
||||||
{
|
{
|
||||||
delete mBeefConfig;
|
delete mBeefConfig;
|
||||||
mBeefConfig = new BeefConfig();
|
mBeefConfig = new BeefConfig();
|
||||||
|
|
|
@ -102,6 +102,15 @@ namespace IDE.util
|
||||||
outPath.AppendF($"{mManagedPath}/{hash}");
|
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)
|
public bool CheckLock(StringView projectName, String outPath, out bool failed)
|
||||||
{
|
{
|
||||||
failed = false;
|
failed = false;
|
||||||
|
@ -121,7 +130,7 @@ namespace IDE.util
|
||||||
switch (lock)
|
switch (lock)
|
||||||
{
|
{
|
||||||
case .Git(let url, let tag, let hash):
|
case .Git(let url, let tag, let hash):
|
||||||
if (mCleanHashSet.Contains(hash))
|
if (WantsHashClean(hash))
|
||||||
return false;
|
return false;
|
||||||
var path = GetPath(url, hash, .. scope .());
|
var path = GetPath(url, hash, .. scope .());
|
||||||
var managedFilePath = scope $"{path}/BeefManaged.toml";
|
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)
|
public void GetWithHash(StringView projectName, StringView url, StringView tag, StringView hash)
|
||||||
{
|
{
|
||||||
if (!CheckInit())
|
if (!CheckInit())
|
||||||
|
@ -202,7 +240,7 @@ namespace IDE.util
|
||||||
Directory.CreateDirectory(urlPath).IgnoreError();
|
Directory.CreateDirectory(urlPath).IgnoreError();
|
||||||
if (Directory.Exists(destPath))
|
if (Directory.Exists(destPath))
|
||||||
{
|
{
|
||||||
if (!mCleanHashSet.ContainsAlt(hash))
|
if (!WantsHashClean(hash))
|
||||||
{
|
{
|
||||||
var managedFilePath = scope $"{destPath}/BeefManaged.toml";
|
var managedFilePath = scope $"{destPath}/BeefManaged.toml";
|
||||||
if (File.Exists(managedFilePath))
|
if (File.Exists(managedFilePath))
|
||||||
|
@ -221,23 +259,7 @@ namespace IDE.util
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String tempDir = new $"{destPath}__{(int32)Internal.GetTickCountMicro():X}";
|
DeleteDir(destPath);
|
||||||
|
|
||||||
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;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gApp.mVerbosity >= .Normal)
|
if (gApp.mVerbosity >= .Normal)
|
||||||
|
@ -509,5 +531,27 @@ namespace IDE.util
|
||||||
Fail("Aborted project transfer");
|
Fail("Aborted project transfer");
|
||||||
mWorkItems.ClearAndDeleteItems();
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue