in src/DependencyManagement/DependencySnapshotInstaller.cs [40:106]
public void InstallSnapshot(
IEnumerable<DependencyManifestEntry> dependencies,
string targetPath,
PowerShell pwsh,
DependencySnapshotInstallationMode installationMode,
ILogger logger)
{
var installingPath = CreateInstallingSnapshot(targetPath);
logger.Log(
isUserOnlyLog: false,
LogLevel.Trace,
string.Format(
PowerShellWorkerStrings.InstallingFunctionAppRequiredModules,
installingPath,
installationMode));
try
{
foreach (DependencyInfo module in GetExactVersionsOfDependencies(dependencies))
{
InstallModule(module, installingPath, pwsh, logger);
}
_snapshotContentLogger.LogDependencySnapshotContent(installingPath, logger);
switch (installationMode)
{
case DependencySnapshotInstallationMode.Optional:
// If the new snapshot turns out to be equivalent to the latest one,
// removing it helps us save storage space and avoid unnecessary worker restarts.
// It is ok to do that during background upgrade because the current
// worker already has a good enough snapshot, and nothing depends on
// the new snapshot yet.
PromoteToInstalledOrRemove(installingPath, targetPath, installationMode, logger);
break;
case DependencySnapshotInstallationMode.Required:
// Even if the new snapshot turns out to be equivalent to the latest one,
// removing it would not be safe because the current worker already depends
// on it, as it has the path to this snapshot already added to PSModulePath.
// As opposed to the background upgrade case, this snapshot is *required* for
// this worker to run, even though it occupies some space (until the workers
// restart and the redundant snapshots are purged).
PromoteToInstalled(installingPath, targetPath, installationMode, logger);
break;
default:
throw new ArgumentException($"Unexpected installation mode: {installationMode}", nameof(installationMode));
}
}
catch (Exception e)
{
var message = string.Format(
PowerShellWorkerStrings.FailedToInstallDependenciesSnapshot,
targetPath,
installationMode);
logger.Log(isUserOnlyLog: false, LogLevel.Warning, message, e);
_storage.RemoveSnapshot(installingPath);
throw;
}
finally
{
_moduleProvider.Cleanup(pwsh);
}
}