2025-02-27 10:53:35 +01:00
|
|
|
|
using Logging;
|
2025-02-27 11:04:04 +01:00
|
|
|
|
using Utils;
|
2025-02-27 10:53:35 +01:00
|
|
|
|
|
|
|
|
|
|
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;
|
2025-02-27 11:04:04 +01:00
|
|
|
|
var padded = new ByteSize(Convert.ToInt64(fileSize * 1.1));
|
2025-02-27 10:53:35 +01:00
|
|
|
|
var space = instance.Node.Space();
|
2025-02-27 11:04:04 +01:00
|
|
|
|
var free = new ByteSize(space.FreeBytes);
|
|
|
|
|
|
|
|
|
|
|
|
log.Log($"Quota free: {free} - filesize: {padded}");
|
|
|
|
|
|
return free.SizeInBytes > padded.SizeInBytes;
|
2025-02-27 10:53:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|