This repository has been archived on 2025-09-07. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
dotnet-installer/src/dotnet/ToolPackage/ToolPackageStore.cs

43 lines
1.2 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Extensions.EnvironmentAbstractions;
namespace Microsoft.DotNet.ToolPackage
{
internal class ToolPackageStore : IToolPackageStore
{
public ToolPackageStore(DirectoryPath root)
{
Root = root;
}
public DirectoryPath Root { get; private set; }
public IEnumerable<IToolPackage> GetInstalledPackages(string packageId)
{
if (packageId == null)
{
throw new ArgumentNullException(nameof(packageId));
}
var packageRootDirectory = Root.WithSubDirectories(packageId);
if (!Directory.Exists(packageRootDirectory.Value))
{
yield break;
}
foreach (var subdirectory in Directory.EnumerateDirectories(packageRootDirectory.Value))
{
var version = Path.GetFileName(subdirectory);
yield return new ToolPackageInstance(
this,
packageId,
version,
packageRootDirectory.WithSubDirectories(version));
}
}
}
}