Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions src/Adeotek.Extensions.Containers/ContainersCli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,7 @@ public int CreateVolume(string volumeName, bool dryRun = false)

public int CreateBindVolume(VolumeConfig volume, bool dryRun = false)
{
var changes = 0;
LogCommand("mkdir", volume.Source);
if (!dryRun)
{
Directory.CreateDirectory(volume.Source);
changes++;
}

var changes = CreateVolumeDirectory(volume.Source, dryRun);
if (ShellCommand.IsWindowsPlatform)
{
return changes;
Expand Down Expand Up @@ -551,6 +544,27 @@ public bool ArchiveVolume(string volumeName, string archiveFile, bool dryRun = f
throw new ContainersCliException("run", 1, $"Unable to archive volume '{volumeName}' into '{archiveFile}'!");
}

protected int CreateVolumeDirectory(string volumeSource, bool dryRun = false)
{
var missingPath = volumeSource.EndsWith(Path.DirectorySeparatorChar)
? volumeSource[..^1]
: Path.GetDirectoryName(volumeSource);

if (string.IsNullOrEmpty(missingPath) || Directory.Exists(missingPath))
{
return 0;
}

LogCommand("mkdir", missingPath);
if (dryRun)
{
return 0;
}

Directory.CreateDirectory(missingPath);
return 1;
}

protected void LogMessage(string message, string level = "info")
{
if (OnContainersCliEvent is null)
Expand Down