/// <summary> /// Cleans local build products for a given node. Does not modify shared storage. /// </summary> /// <param name="NodeName">Name of the node</param> public void CleanLocalNode(string NodeName) { DirectoryReference NodeDir = GetDirectoryForNode(LocalDir, NodeName); if (NodeDir.Exists()) { CommandUtils.DeleteDirectoryContents(NodeDir.FullName); CommandUtils.DeleteDirectory_NoExceptions(NodeDir.FullName); } }
/// <summary> /// Entry point for the commandlet /// </summary> public override void ExecuteBuild() { string ReportDir = ParseParamValue("ReportDir", null); if (ReportDir == null) { throw new AutomationException("Missing -ReportDir parameter"); } string Days = ParseParamValue("Days", null); if (Days == null) { throw new AutomationException("Missing -Days parameter"); } double DaysValue; if (!Double.TryParse(Days, out DaysValue)) { throw new AutomationException("'{0}' is not a valid value for the -Days parameter", Days); } DateTime RetainTime = DateTime.UtcNow - TimeSpan.FromDays(DaysValue); // Enumerate all the build directories CommandUtils.LogInformation("Scanning {0}...", ReportDir); int NumFolders = 0; List <DirectoryInfo> FoldersToDelete = new List <DirectoryInfo>(); foreach (DirectoryInfo BuildDirectory in new DirectoryInfo(ReportDir).EnumerateDirectories()) { if (!BuildDirectory.EnumerateFiles("*", SearchOption.AllDirectories).Any(x => x.LastWriteTimeUtc > RetainTime)) { FoldersToDelete.Add(BuildDirectory); } NumFolders++; } CommandUtils.LogInformation("Found {0} builds; {1} to delete.", NumFolders, FoldersToDelete.Count); // Delete them all for (int Idx = 0; Idx < FoldersToDelete.Count; Idx++) { try { CommandUtils.LogInformation("[{0}/{1}] Deleting {2}...", Idx + 1, FoldersToDelete.Count, FoldersToDelete[Idx].FullName); FoldersToDelete[Idx].Delete(true); } catch (Exception Ex) { CommandUtils.LogWarning("Failed to delete folder; will try one file at a time: {0}", Ex); CommandUtils.DeleteDirectory_NoExceptions(true, FoldersToDelete[Idx].FullName); } } }
/// <summary> /// Entry point for the commandlet /// </summary> public override void ExecuteBuild() { string ReportDir = ParseRequiredStringParam("ReportDir"); string Days = ParseRequiredStringParam("Days"); double DaysValue; if (!Double.TryParse(Days, out DaysValue)) { throw new AutomationException("'{0}' is not a valid value for the -Days parameter", Days); } string Depth = ParseOptionalStringParam("Depth"); int TargetDepth; if (!int.TryParse(Depth, out TargetDepth)) { TargetDepth = 0; } DirectoryInfo ReportDirInfo = new DirectoryInfo(ReportDir); if (!ReportDirInfo.Exists) { throw new AutomationException("Report directory '{0}' does not exists.", ReportDirInfo.FullName); } DateTime RetainTime = DateTime.UtcNow - TimeSpan.FromDays(DaysValue); List <DirectoryInfo> DirectoriesToDelete = new List <DirectoryInfo>(); int DirsScanned = CleanDirectories(ReportDirInfo, RetainTime, DirectoriesToDelete, TargetDepth); // Delete old folders. CommandUtils.LogInformation("Found {0} builds; {1} to delete.", DirsScanned, DirectoriesToDelete.Count); for (int Idx = 0; Idx < DirectoriesToDelete.Count; Idx++) { try { CommandUtils.LogInformation("[{0}/{1}] Deleting {2}...", Idx + 1, DirectoriesToDelete.Count, DirectoriesToDelete[Idx].FullName); DirectoriesToDelete[Idx].Delete(true); } catch (Exception Ex) { CommandUtils.LogWarning("Failed to delete folder; will try one file at a time: {0}", Ex); CommandUtils.DeleteDirectory_NoExceptions(true, DirectoriesToDelete[Idx].FullName); } } }