public virtual void RebuildCache() { LoggingService.Log(new LogEntry(LogLevel.Info, null, $"Rebuilding index cache {RootFolder}")); try { ClearCache(); } catch (Exception e) { LoggingService.Log(new LogEntry(LogLevel.Error, e, $"Exception thrown while rebuilding cache for {RootFolder}")); } foreach (string file in GetAllBlobFiles()) { CacheDirectory.TouchFile(file); RemoteDirectory.SyncFile(CacheDirectory, file, CompressBlobs); } }
public RemoteDirectoryIndexInput(RemoteSyncDirectory azuredirectory, IRemoteDirectory helper, string name, ILoggingService loggingService) { _name = name; _name = _name.Split(new string[] { "%2F" }, StringSplitOptions.RemoveEmptyEntries).Last(); _remoteSyncDirectory = azuredirectory ?? throw new ArgumentNullException(nameof(azuredirectory)); #if FULLDEBUG Trace.WriteLine($"opening {_name} "); #endif _fileMutex = SyncMutexManager.GrabMutex(_remoteSyncDirectory, _name); _fileMutex.WaitOne(); try { var fileName = _name; var fFileNeeded = false; if (!CacheDirectory.FileExists(fileName)) { fFileNeeded = true; } else { var cachedLength = CacheDirectory.FileLength(fileName); var blobProperties = helper.GetFileProperties(fileName); if (cachedLength != blobProperties.Item1) { fFileNeeded = true; } else { // cachedLastModifiedUTC was not ouputting with a date (just time) and the time was always off var unixDate = CacheDirectory.FileModified(fileName); var start = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); var cachedLastModifiedUtc = start.AddMilliseconds(unixDate).ToUniversalTime(); if (cachedLastModifiedUtc != blobProperties.Item2) { var timeSpan = blobProperties.Item2.Subtract(cachedLastModifiedUtc); if (timeSpan.TotalSeconds > 1) { fFileNeeded = true; } else { #if FULLDEBUG Trace.WriteLine(timeSpan.TotalSeconds); #endif // file not needed } } } } // if the file does not exist // or if it exists and it is older then the lastmodified time in the blobproperties (which always comes from the blob storage) if (fFileNeeded) { helper.SyncFile(CacheDirectory, fileName, azuredirectory.CompressBlobs); // and open it as an input _indexInput = CacheDirectory.OpenInput(fileName); } else { #if FULLDEBUG Trace.WriteLine($"Using cached file for {_name}"); #endif // open the file in read only mode _indexInput = CacheDirectory.OpenInput(fileName); } } finally { _fileMutex.ReleaseMutex(); } }