Skip to content

Commit 9bae331

Browse files
committed
replace simple link-target check with info probing
1 parent d672fda commit 9bae331

File tree

1 file changed

+13
-6
lines changed
  • src/Containers/Microsoft.NET.Build.Containers/LocalDaemons

1 file changed

+13
-6
lines changed

src/Containers/Microsoft.NET.Build.Containers/LocalDaemons/DockerCli.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,15 +302,22 @@ await Task.WhenAll(
302302

303303
private static bool IsPodmanAlias()
304304
{
305-
var dockerPath = FindFullPathFromPath(DockerCommand);
306-
var podmanPath = FindFullPathFromPath(PodmanCommand);
307-
if (dockerPath is null || podmanPath is null)
305+
// If both exist we need to check and see if the docker command is actually docker,
306+
// or if it is a podman script in a trenchcoat.
307+
try
308+
{
309+
var dockerinfo = GetConfig().RootElement;
310+
// Docker's info output has a 'DockerRootDir' top-level property string that is a good marker,
311+
// while Podman has a 'host' top-level property object with a 'buildahVersion' subproperty
312+
var hasdockerProperty =
313+
dockerinfo.TryGetProperty("DockerRootDir", out var dockerRootDir) && dockerRootDir.GetString() is not null;
314+
var hasPodmanProperty = dockerinfo.TryGetProperty("host", out var host) && host.TryGetProperty("buildahVersion", out var buildahVersion) && buildahVersion.GetString() is not null;
315+
return !hasdockerProperty && hasPodmanProperty;
316+
}
317+
catch
308318
{
309319
return false;
310320
}
311-
312-
var fi = new FileInfo(dockerPath);
313-
return fi.LinkTarget == podmanPath;
314321
}
315322

316323
private async Task<bool> TryRunVersionCommandAsync(string command, CancellationToken cancellationToken)

0 commit comments

Comments
 (0)