Trying a different method of setting access time.

This commit is contained in:
defnotken
2025-12-23 10:36:38 -06:00
parent 33fb6ba2eb
commit 4012b33f98

View File

@@ -102,36 +102,37 @@ public sealed class CachedFileProvider : IDisposable
private bool TryCopyFromColdStorage(string hash, string destinationFilePath) private bool TryCopyFromColdStorage(string hash, string destinationFilePath)
{ {
if (!_configuration.GetValueOrDefault(nameof(StaticFilesServerConfiguration.UseColdStorage), false)) return false; if (!_configuration.GetValueOrDefault(nameof(StaticFilesServerConfiguration.UseColdStorage), false)) return false;
string coldStorageDir = _configuration.GetValueOrDefault(nameof(StaticFilesServerConfiguration.ColdStorageDirectory), string.Empty); string coldStorageDir = _configuration.GetValueOrDefault(nameof(StaticFilesServerConfiguration.ColdStorageDirectory), string.Empty);
if (string.IsNullOrEmpty(coldStorageDir)) return false; if (string.IsNullOrEmpty(coldStorageDir)) return false;
var coldStorageFilePath = FilePathUtil.GetFileInfoForHash(coldStorageDir, hash); var coldStorageFilePath = FilePathUtil.GetFileInfoForHash(coldStorageDir, hash);
if (coldStorageFilePath == null) return false; if (coldStorageFilePath == null) return false;
try try
{ {
_logger.LogDebug("Copying {hash} from cold storage: {path}", hash, coldStorageFilePath); _logger.LogDebug("Copying {hash} from cold storage: {path}", hash, coldStorageFilePath);
var tempFileName = destinationFilePath + ".dl"; var tempFileName = destinationFilePath + ".dl";
File.Copy(coldStorageFilePath.FullName, tempFileName, true); File.Copy(coldStorageFilePath.FullName, tempFileName, true);
File.Move(tempFileName, destinationFilePath, true); File.Move(tempFileName, destinationFilePath, true);
coldStorageFilePath.LastAccessTimeUtc = DateTime.UtcNow;
var destinationFile = new FileInfo(destinationFilePath);
destinationFile.LastAccessTimeUtc = DateTime.UtcNow;
destinationFile.CreationTimeUtc = DateTime.UtcNow;
destinationFile.LastWriteTimeUtc = DateTime.UtcNow;
_metrics.IncGauge(MetricsAPI.GaugeFilesTotal);
_metrics.IncGauge(MetricsAPI.GaugeFilesTotalSize, new FileInfo(destinationFilePath).Length);
return true;
}
catch (Exception ex)
{
_logger.LogWarning(ex, "Could not copy {coldStoragePath} from cold storage", coldStorageFilePath);
}
return false; File.SetLastAccessTimeUtc(coldStorageFilePath.FullName, DateTime.UtcNow);
} File.SetLastAccessTimeUtc(destinationFilePath, DateTime.UtcNow);
File.SetCreationTimeUtc(destinationFilePath, DateTime.UtcNow);
File.SetLastWriteTimeUtc(destinationFilePath, DateTime.UtcNow);
_metrics.IncGauge(MetricsAPI.GaugeFilesTotal);
_metrics.IncGauge(MetricsAPI.GaugeFilesTotalSize, new FileInfo(destinationFilePath).Length);
return true;
}
catch (Exception ex)
{
_logger.LogWarning(ex, "Could not copy {coldStoragePath} from cold storage", coldStorageFilePath);
}
return false;
}
public async Task DownloadFileWhenRequired(string hash) public async Task DownloadFileWhenRequired(string hash)
{ {
@@ -170,15 +171,22 @@ public sealed class CachedFileProvider : IDisposable
public FileInfo? GetLocalFilePath(string hash) public FileInfo? GetLocalFilePath(string hash)
{ {
var fi = FilePathUtil.GetFileInfoForHash(_hotStoragePath, hash); var fi = FilePathUtil.GetFileInfoForHash(_hotStoragePath, hash);
if (fi == null) return null; if (fi == null) return null;
fi.LastAccessTimeUtc = DateTime.UtcNow; try
{
File.SetLastAccessTimeUtc(fi.FullName, DateTime.UtcNow);
}
catch (Exception ex)
{
_logger.LogWarning(ex, "Failed to update LastAccessTimeUtc for file {hash}", hash);
}
_fileStatisticsService.LogFile(hash, fi.Length); _fileStatisticsService.LogFile(hash, fi.Length);
return new FileInfo(fi.FullName); return new FileInfo(fi.FullName);
} }
public async Task<FileInfo?> DownloadAndGetLocalFileInfo(string hash) public async Task<FileInfo?> DownloadAndGetLocalFileInfo(string hash)
{ {