GetAdvertisingManifestVersionAndWorkloads(ManifestId manifestId) { var manifestPath = Path.Combine(GetAdvertisingManifestPath(_sdkFeatureBand, manifestId), "WorkloadManifest.json"); if (!File.Exists(manifestPath)) { return(null); } using (FileStream fsSource = new FileStream(manifestPath, FileMode.Open, FileAccess.Read)) { var manifest = WorkloadManifestReader.ReadWorkloadManifest(manifestId.ToString(), fsSource, manifestPath); // we need to know the feature band of the advertised manifest (read it from the AdvertisedManifestFeatureBand.txt file) // if we don't find the file then use the current feature band var adManifestFeatureBandPath = Path.Combine(GetAdvertisingManifestPath(_sdkFeatureBand, manifestId), "AdvertisedManifestFeatureBand.txt"); SdkFeatureBand adManifestFeatureBand = _sdkFeatureBand; if (File.Exists(adManifestFeatureBandPath)) { adManifestFeatureBand = new SdkFeatureBand(File.ReadAllText(adManifestFeatureBandPath)); } return(new ManifestVersion(manifest.Version), adManifestFeatureBand, manifest.Workloads.Values.OfType <WorkloadDefinition>().ToDictionary(w => w.Id)); } }
private ManifestVersion GetAdvertisingManifestVersion(ManifestId manifestId) { var manifestPath = Path.Combine(GetAdvertisingManifestPath(_sdkFeatureBand, manifestId), "WorkloadManifest.json"); if (!File.Exists(manifestPath)) { return(null); } using (FileStream fsSource = new FileStream(manifestPath, FileMode.Open, FileAccess.Read)) { var manifest = WorkloadManifestReader.ReadWorkloadManifest(manifestId.ToString(), fsSource); return(new ManifestVersion(manifest.Version)); } }
GetAdvertisingManifestVersionAndWorkloads(ManifestId manifestId) { var manifestPath = Path.Combine(GetAdvertisingManifestPath(_sdkFeatureBand, manifestId), "WorkloadManifest.json"); if (!File.Exists(manifestPath)) { return(null); } using (FileStream fsSource = new FileStream(manifestPath, FileMode.Open, FileAccess.Read)) { var manifest = WorkloadManifestReader.ReadWorkloadManifest(manifestId.ToString(), fsSource); return(new ManifestVersion(manifest.Version), manifest.Workloads.Values.OfType <WorkloadDefinition>().ToDictionary(w => w.Id)); } }
private ManifestVersion GetInstalledManifestVersion(ManifestId manifestId) { var manifestDir = _workloadManifestProvider.GetManifestDirectories() .FirstOrDefault(dir => Path.GetFileName(dir).ToLowerInvariant().Equals(manifestId.ToString())); if (manifestDir == null) { throw new Exception(string.Format(LocalizableStrings.ManifestDoesNotExist, manifestId.ToString())); } var manifestPath = Path.Combine(manifestDir, "WorkloadManifest.json"); if (!File.Exists(manifestPath)) { throw new Exception(string.Format(LocalizableStrings.ManifestDoesNotExist, manifestId.ToString())); } using (FileStream fsSource = new FileStream(manifestPath, FileMode.Open, FileAccess.Read)) { var manifest = WorkloadManifestReader.ReadWorkloadManifest(manifestId.ToString(), fsSource); return(new ManifestVersion(manifest.Version)); } }
public void InstallWorkloadManifest(ManifestId manifestId, ManifestVersion manifestVersion, SdkFeatureBand sdkFeatureBand, DirectoryPath?offlineCache = null, bool isRollback = false) { string packagePath = null; string tempExtractionDir = null; string tempBackupDir = null; string rootInstallDir = WorkloadFileBasedInstall.IsUserLocal(_dotnetDir, sdkFeatureBand.ToString()) ? _userProfileDir : _dotnetDir; var manifestPath = Path.Combine(rootInstallDir, "sdk-manifests", sdkFeatureBand.ToString(), manifestId.ToString()); _reporter.WriteLine(string.Format(LocalizableStrings.InstallingWorkloadManifest, manifestId, manifestVersion)); try { TransactionalAction.Run( action: () => { if (offlineCache == null || !offlineCache.HasValue) { packagePath = _nugetPackageDownloader.DownloadPackageAsync(WorkloadManifestUpdater.GetManifestPackageId(sdkFeatureBand, manifestId), new NuGetVersion(manifestVersion.ToString()), _packageSourceLocation).GetAwaiter().GetResult(); } else { packagePath = Path.Combine(offlineCache.Value.Value, $"{WorkloadManifestUpdater.GetManifestPackageId(sdkFeatureBand, manifestId)}.{manifestVersion}.nupkg"); if (!File.Exists(packagePath)) { throw new Exception(string.Format(LocalizableStrings.CacheMissingPackage, WorkloadManifestUpdater.GetManifestPackageId(sdkFeatureBand, manifestId), manifestVersion, offlineCache)); } } tempExtractionDir = Path.Combine(_tempPackagesDir.Value, $"{manifestId}-{manifestVersion}-extracted"); Directory.CreateDirectory(tempExtractionDir); var manifestFiles = _nugetPackageDownloader.ExtractPackageAsync(packagePath, new DirectoryPath(tempExtractionDir)).GetAwaiter().GetResult(); if (Directory.Exists(manifestPath) && Directory.GetFileSystemEntries(manifestPath).Any()) { // Backup existing manifest data for roll back purposes tempBackupDir = Path.Combine(_tempPackagesDir.Value, $"{manifestId}-{manifestVersion}-backup"); if (Directory.Exists(tempBackupDir)) { Directory.Delete(tempBackupDir, true); } FileAccessRetrier.RetryOnMoveAccessFailure(() => DirectoryPath.MoveDirectory(manifestPath, tempBackupDir)); } Directory.CreateDirectory(Path.GetDirectoryName(manifestPath)); FileAccessRetrier.RetryOnMoveAccessFailure(() => DirectoryPath.MoveDirectory(Path.Combine(tempExtractionDir, "data"), manifestPath)); }, rollback: () => { if (!string.IsNullOrEmpty(tempBackupDir) && Directory.Exists(tempBackupDir)) { FileAccessRetrier.RetryOnMoveAccessFailure(() => DirectoryPath.MoveDirectory(tempBackupDir, manifestPath)); } }); // Delete leftover dirs and files if (!string.IsNullOrEmpty(packagePath) && File.Exists(packagePath) && (offlineCache == null || !offlineCache.HasValue)) { File.Delete(packagePath); } var versionDir = Path.GetDirectoryName(packagePath); if (Directory.Exists(versionDir) && !Directory.GetFileSystemEntries(versionDir).Any()) { Directory.Delete(versionDir); var idDir = Path.GetDirectoryName(versionDir); if (Directory.Exists(idDir) && !Directory.GetFileSystemEntries(idDir).Any()) { Directory.Delete(idDir); } } if (!string.IsNullOrEmpty(tempExtractionDir) && Directory.Exists(tempExtractionDir)) { Directory.Delete(tempExtractionDir, true); } if (!string.IsNullOrEmpty(tempBackupDir) && Directory.Exists(tempBackupDir)) { Directory.Delete(tempBackupDir, true); } } catch (Exception e) { throw new Exception(string.Format(LocalizableStrings.FailedToInstallWorkloadManifest, manifestId, manifestVersion, e.Message)); } }
private string GetAdvertisingManifestPath(SdkFeatureBand featureBand, ManifestId manifestId) => Path.Combine(_userHome, ".dotnet", "sdk-advertising", featureBand.ToString(), manifestId.ToString());
private async Task <bool> NewerManifestPackageExists(ManifestId manifest) { try { var currentVersion = NuGetVersion.Parse(_workloadResolver.GetManifestVersion(manifest.ToString())); var latestVersion = await _nugetPackageDownloader.GetLatestPackageVerion(GetManifestPackageId(_sdkFeatureBand, manifest)); return(latestVersion > currentVersion); } catch (Exception) { return(false); } }
private string GetAdvertisingManifestPath(SdkFeatureBand featureBand, ManifestId manifestId) => Path.Combine(_userProfileDir, "sdk-advertising", featureBand.ToString(), manifestId.ToString());
private ManifestVersion GetInstalledManifestVersion(ManifestId manifestId) { var manifest = _workloadResolver.GetInstalledManifests() .FirstOrDefault(manifest => manifest.Id.ToLowerInvariant().Equals(manifestId.ToString())); if (manifest == null) { throw new Exception(string.Format(LocalizableStrings.ManifestDoesNotExist, manifestId.ToString())); } return(new ManifestVersion(manifest.Version)); }
public void InstallWorkloadManifest(ManifestId manifestId, ManifestVersion manifestVersion, SdkFeatureBand sdkFeatureBand) { string packagePath = null; string tempExtractionDir = null; string tempBackupDir = null; var manifestPath = Path.Combine(_dotnetDir, "sdk-manifests", sdkFeatureBand.ToString(), manifestId.ToString()); _reporter.WriteLine(string.Format(LocalizableStrings.InstallingWorkloadManifest, manifestId, manifestVersion)); try { TransactionalAction.Run( action: () => { packagePath = _nugetPackageDownloader.DownloadPackageAsync(WorkloadManifestUpdater.GetManifestPackageId(sdkFeatureBand, manifestId), new NuGetVersion(manifestVersion.ToString())).Result; tempExtractionDir = Path.Combine(_tempPackagesDir.Value, $"{manifestId}-{manifestVersion}-extracted"); Directory.CreateDirectory(tempExtractionDir); var manifestFiles = _nugetPackageDownloader.ExtractPackageAsync(packagePath, new DirectoryPath(tempExtractionDir)).Result; if (Directory.Exists(manifestPath) && Directory.GetFileSystemEntries(manifestPath).Any()) { // Backup existing manifest data for roll back purposes tempBackupDir = Path.Combine(_tempPackagesDir.Value, $"{manifestId}-{manifestVersion}-backup"); if (Directory.Exists(tempBackupDir)) { Directory.Delete(tempBackupDir, true); } FileAccessRetrier.RetryOnMoveAccessFailure(() => Directory.Move(manifestPath, tempBackupDir)); } Directory.CreateDirectory(Path.GetDirectoryName(manifestPath)); FileAccessRetrier.RetryOnMoveAccessFailure(() => Directory.Move(Path.Combine(tempExtractionDir, "data"), manifestPath)); }, rollback: () => { if (!string.IsNullOrEmpty(tempBackupDir) && Directory.Exists(tempBackupDir)) { FileAccessRetrier.RetryOnMoveAccessFailure(() => Directory.Move(tempBackupDir, manifestPath)); } }); // Delete leftover dirs and files if (!string.IsNullOrEmpty(packagePath) && File.Exists(packagePath)) { File.Delete(packagePath); } var versionDir = Path.GetDirectoryName(packagePath); if (Directory.Exists(versionDir) && !Directory.GetFileSystemEntries(versionDir).Any()) { Directory.Delete(versionDir); var idDir = Path.GetDirectoryName(versionDir); if (Directory.Exists(idDir) && !Directory.GetFileSystemEntries(idDir).Any()) { Directory.Delete(idDir); } } if (!string.IsNullOrEmpty(tempExtractionDir) && Directory.Exists(tempExtractionDir)) { Directory.Delete(tempExtractionDir, true); } if (!string.IsNullOrEmpty(tempBackupDir) && Directory.Exists(tempBackupDir)) { Directory.Delete(tempBackupDir, true); } } catch (Exception e) { throw new Exception(string.Format(LocalizableStrings.FailedToInstallWorkloadManifest, manifestId, manifestVersion, e.Message)); } }