ulong GetRequiredSpaceInBytes(out bool spaceOverrideSpecified) { spaceOverrideSpecified = false; var freeSpaceOverrideInMegaBytes = variables.GetInt32(FreeDiskSpaceOverrideInMegaBytesVariable); if (!freeSpaceOverrideInMegaBytes.HasValue) { return(DefaultRequiredSpaceInBytes); } spaceOverrideSpecified = true; return((ulong)freeSpaceOverrideInMegaBytes * 1024 * 1024); }
public override int Execute(string[] commandLineArguments) { Options.Parse(commandLineArguments); var configurationTransformer = ConfigurationTransformer.FromVariables(variables); var transformFileLocator = new TransformFileLocator(fileSystem); var replacer = new ConfigurationVariablesReplacer(variables.GetFlag(SpecialVariables.Package.IgnoreVariableReplacementErrors)); var jsonVariableReplacer = new JsonConfigurationVariableReplacer(); ValidateArguments(); WriteVariableScriptToFile(); var conventions = new List <IConvention> { new StageScriptPackagesConvention(packageFile, fileSystem, new CombinedPackageExtractor(log)), // Substitute the script source file new DelegateInstallConvention(d => substituteInFiles.Substitute(d, ScriptFileTargetFactory(d).ToList())), // Substitute any user-specified files new DelegateInstallConvention(d => substituteInFiles.SubstituteBasedSettingsInSuppliedVariables(d)), new ConfigurationTransformsConvention(fileSystem, configurationTransformer, transformFileLocator), new ConfigurationVariablesConvention(fileSystem, replacer), new JsonConfigurationVariablesConvention(jsonVariableReplacer, fileSystem), new ExecuteScriptConvention(scriptEngine, commandLineRunner) }; var deployment = new RunningDeployment(packageFile, variables); var conventionRunner = new ConventionProcessor(deployment, conventions); conventionRunner.RunConventions(); var exitCode = variables.GetInt32(SpecialVariables.Action.Script.ExitCode); deploymentJournalWriter.AddJournalEntry(deployment, exitCode == 0, packageFile); return(exitCode.Value); }
public override int Execute(string[] commandLineArguments) { Options.Parse(commandLineArguments); var configurationTransformer = ConfigurationTransformer.FromVariables(variables, log); var transformFileLocator = new TransformFileLocator(fileSystem, log); var replacer = new ConfigurationVariablesReplacer(variables, log); var allFileFormatReplacers = FileFormatVariableReplacers.BuildAllReplacers(fileSystem, log); var structuredConfigVariablesService = new StructuredConfigVariablesService(allFileFormatReplacers, fileSystem, log); ValidateArguments(); WriteVariableScriptToFile(); var conventions = new List <IConvention> { new StageScriptPackagesConvention(packageFile, fileSystem, new CombinedPackageExtractor(log)), // Substitute the script source file new DelegateInstallConvention(d => substituteInFiles.Substitute(d, ScriptFileTargetFactory(d).ToList())), // Substitute any user-specified files new SubstituteInFilesConvention(new SubstituteInFilesBehaviour(substituteInFiles)), new ConfigurationTransformsConvention(new ConfigurationTransformsBehaviour(fileSystem, configurationTransformer, transformFileLocator, log)), new ConfigurationVariablesConvention(new ConfigurationVariablesBehaviour(fileSystem, replacer, log)), new StructuredConfigurationVariablesConvention(new StructuredConfigurationVariablesBehaviour(structuredConfigVariablesService)), new ExecuteScriptConvention(scriptEngine, commandLineRunner) }; var deployment = new RunningDeployment(packageFile, variables); var conventionRunner = new ConventionProcessor(deployment, conventions, log); conventionRunner.RunConventions(); var exitCode = variables.GetInt32(SpecialVariables.Action.Script.ExitCode); deploymentJournalWriter.AddJournalEntry(deployment, exitCode == 0, packageFile); return(exitCode.Value); }
public IEnumerable <PackageIdentity> GetPackagesToRemove(IEnumerable <JournalEntry> journalEntries) { if (!fileSystem.GetDiskFreeSpace(packageUtils.RootDirectory, out var totalNumberOfFreeBytes) || !fileSystem.GetDiskTotalSpace(packageUtils.RootDirectory, out var totalNumberOfBytes)) { log.Info("Unable to determine disk space. Skipping free space package retention."); return(new PackageIdentity[0]); } var percentFreeDiskSpaceDesired = variables.GetInt32(PackageRetentionPercentFreeDiskSpace) ?? DefaultPercentFreeDiskSpace; var desiredSpaceInBytes = totalNumberOfBytes * (ulong)percentFreeDiskSpaceDesired / 100; if (totalNumberOfFreeBytes > desiredSpaceInBytes) { log.VerboseFormat("Detected enough space for new packages. ({0}/{1})", totalNumberOfFreeBytes.ToFileSizeString(), totalNumberOfBytes.ToFileSizeString()); return(new PackageIdentity[0]); } var spaceToFree = (desiredSpaceInBytes - totalNumberOfFreeBytes) * (100 + FreeSpacePercentBuffer) / 100; log.VerboseFormat("Cleaning {0} space from the package cache.", spaceToFree.ToFileSizeString()); ulong spaceFreed = 0L; var orderedJournalEntries = sortJournalEntries.Sort(journalEntries); return(orderedJournalEntries.TakeWhile(entry => { var moreToClean = spaceFreed < spaceToFree; spaceFreed += entry.FileSizeBytes; return moreToClean; }) .Select(entry => entry.Package)); }
public void EnsureDiskHasEnoughFreeSpace(string directoryPath) { if (CalamariEnvironment.IsRunningOnMono && CalamariEnvironment.IsRunningOnMac) { //After upgrading to macOS 10.15.2, and mono 5.14.0, drive.TotalFreeSpace and drive.AvailableFreeSpace both started returning 0. //see https://github.com/mono/mono/issues/17151, which was fixed in mono 6.4.xx //If we upgrade mono past 5.14.x, scriptcs stops working. //Rock and a hard place. Log.Verbose("Unable to determine disk free space under Mono on macOS. Assuming there's enough."); return; } if (variables.GetFlag(skipFreeDiskSpaceCheckVariable)) { Log.Verbose($"{skipFreeDiskSpaceCheckVariable} is enabled. The check to ensure that the drive containing the directory '{directoryPath}' on machine '{Environment.MachineName}' has enough free space will be skipped."); return; } ulong requiredSpaceInBytes = 500L * 1024 * 1024; var freeSpaceOverrideInMegaBytes = variables.GetInt32(freeDiskSpaceOverrideInMegaBytesVariable); if (freeSpaceOverrideInMegaBytes.HasValue) { requiredSpaceInBytes = (ulong)freeSpaceOverrideInMegaBytes * 1024 * 1024; Log.Verbose($"{freeDiskSpaceOverrideInMegaBytesVariable} has been specified. We will check and ensure that the drive containing the directory '{directoryPath}' on machine '{Environment.MachineName}' has {((ulong) requiredSpaceInBytes).ToFileSizeString()} free disk space."); } var success = fileSystem.GetDiskFreeSpace(directoryPath, out ulong totalNumberOfFreeBytes); if (!success) { return; } if (totalNumberOfFreeBytes < requiredSpaceInBytes) { throw new CommandException($"The drive containing the directory '{directoryPath}' on machine '{Environment.MachineName}' does not have enough free disk space available for this operation to proceed. The disk only has {totalNumberOfFreeBytes.ToFileSizeString()} available; please free up at least {requiredSpaceInBytes.ToFileSizeString()}."); } }