/// <summary> /// /// </summary> public void RecieveReplicatedBuilds(NetMessage_GetFilteredBuildsResponse.BuildInfo[] Builds) { if (!AutoReplicate) { return; } Logger.Log(LogLevel.Info, LogCategory.Download, "Recieved {0} replicated builds from server.", Builds.Length); foreach (NetMessage_GetFilteredBuildsResponse.BuildInfo Build in Builds) { Logger.Log(LogLevel.Info, LogCategory.Download, "\tBuild:{0} Path:{1}", Build.Guid.ToString(), Build.VirtualPath); // Manifest is being manipulated elsewhere. if (ManifestDownloader.IsDownloadBlocked(Build.Guid)) { continue; } // Already downloaded/downloading. ManifestDownloadState State = ManifestDownloader.GetDownload(Build.Guid); if (State != null) { continue; } // Create a new download. AddDownload( "Automatic Replication", Build.VirtualPath, 0, BuildSelectionRule.Newest, BuildSelectionFilter.None, "", "", false, false, "", "", new List <Guid>(), new List <Guid>(), true ); } }
/// <summary> /// </summary> public void PruneDiskSpace() { if (TimeUtils.Ticks - TimeSinceLastPruneRequest < 60 * 1000) { return; } if (PendingDirectoryCleanups.Count > 0) { return; } if (CleanUpOrphanBuilds()) { return; } if (DeleteIncompleteBuilds()) { return; } foreach (StorageLocation Location in Locations) { string NormalizedLocationPath = FileUtils.NormalizePath(Location.Path); long UsedSpace = GetLocationDiskUsage(Location); long FreeSpace = GetLocationFreeSpace(Location, true); if (FreeSpace < Location.MinimumSpaceOnDrive || UsedSpace > Location.MaxSize) { // Select manifests for deletion in this location. List <ManifestDownloadState> DeletionCandidates = new List <ManifestDownloadState>(); foreach (ManifestDownloadState State in DownloadManager.States.States) { // This download is currently being worked on, don't try and clean it up. if (DownloadManager.IsDownloadBlocked(State.ManifestId)) { continue; } // Not even got an allocated folder yet. if (State.LocalFolder == "") { continue; } // Not part of this storage location. if (!FileUtils.NormalizePath(State.LocalFolder).StartsWith(NormalizedLocationPath)) { continue; } // Active or no local folder allocated yet. if (State.Active || State.LocalFolder == "") { continue; } // No manifest yet. if (State.Manifest == null) { continue; } // Something is active in the directory. if (FileUtils.AnyRunningProcessesInDirectory(State.LocalFolder)) { continue; } DeletionCandidates.Add(State); } if (DeletionCandidates.Count > 0) { DeletionCandidates.Sort((Item1, Item2) => Item1.LastActive.CompareTo(Item2.LastActive)); // Request the server to select the next candidate for deletion. List <Guid> DeletionCandidatesIds = new List <Guid>(); foreach (ManifestDownloadState State in DeletionCandidates) { DeletionCandidatesIds.Add(State.ManifestId); } OnRequestChooseDeletionCandidate?.Invoke(DeletionCandidatesIds, StorageHeuristic, StoragePrioritizeKeepingBuildTagIds, StoragePrioritizeDeletingBuildTagIds); } TimeSinceLastPruneRequest = TimeUtils.Ticks; } } }