mirror of
https://github.com/logos-storage/logos-storage-nim-cs-dist-tests.git
synced 2026-02-27 00:03:08 +00:00
Considers local quota before uploading.
This commit is contained in:
parent
3ab1e2ea47
commit
a96a9ce319
@ -11,6 +11,7 @@ namespace AutoClient.Modes.FolderStore
|
||||
private readonly Stats stats;
|
||||
private readonly string folderFile;
|
||||
private readonly FileStatus entry;
|
||||
private readonly QuotaCheck quotaCheck;
|
||||
|
||||
public FileSaver(ILog log, CodexWrapper instance, Stats stats, string folderFile, FileStatus entry)
|
||||
{
|
||||
@ -19,6 +20,8 @@ namespace AutoClient.Modes.FolderStore
|
||||
this.stats = stats;
|
||||
this.folderFile = folderFile;
|
||||
this.entry = entry;
|
||||
|
||||
quotaCheck = new QuotaCheck(log, folderFile, instance);
|
||||
}
|
||||
|
||||
public bool HasFailed { get; private set; }
|
||||
@ -45,7 +48,10 @@ namespace AutoClient.Modes.FolderStore
|
||||
Log("BasicCid is available.");
|
||||
return;
|
||||
}
|
||||
UploadFile();
|
||||
if (QuotaAvailable())
|
||||
{
|
||||
UploadFile();
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsBasicCidAvailable()
|
||||
@ -54,6 +60,22 @@ namespace AutoClient.Modes.FolderStore
|
||||
return NodeContainsBasicCid();
|
||||
}
|
||||
|
||||
private bool QuotaAvailable()
|
||||
{
|
||||
if (quotaCheck.IsLocalQuotaAvailable()) return true;
|
||||
Log("Waiting for local storage quota to become available...");
|
||||
|
||||
var timeLimit = DateTime.UtcNow + TimeSpan.FromHours(1.0);
|
||||
while (DateTime.UtcNow < timeLimit)
|
||||
{
|
||||
if (quotaCheck.IsLocalQuotaAvailable()) return true;
|
||||
Thread.Sleep(TimeSpan.FromMinutes(1.0));
|
||||
}
|
||||
Log("Could not upload: Insufficient local storage quota.");
|
||||
HasFailed = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool HasRecentPurchase(FileStatus entry)
|
||||
{
|
||||
if (string.IsNullOrEmpty(entry.PurchaseId)) return false;
|
||||
|
||||
41
Tools/AutoClient/Modes/FolderStore/QuotaCheck.cs
Normal file
41
Tools/AutoClient/Modes/FolderStore/QuotaCheck.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using Logging;
|
||||
|
||||
namespace AutoClient.Modes.FolderStore
|
||||
{
|
||||
public class QuotaCheck
|
||||
{
|
||||
private readonly ILog log;
|
||||
private readonly string filepath;
|
||||
private readonly CodexWrapper instance;
|
||||
|
||||
public QuotaCheck(ILog log, string filepath, CodexWrapper instance)
|
||||
{
|
||||
this.log = log;
|
||||
this.filepath = filepath;
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public bool IsLocalQuotaAvailable()
|
||||
{
|
||||
try
|
||||
{
|
||||
return CheckQuota();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
log.Error("Failed to check quota: " + exc);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private bool CheckQuota()
|
||||
{
|
||||
var info = new FileInfo(filepath);
|
||||
var fileSize = info.Length;
|
||||
var padded = fileSize * 1.1;
|
||||
|
||||
var space = instance.Node.Space();
|
||||
return space.FreeBytes > padded;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user