Skip to content

Commit

Permalink
added to Microsoft.DotNet.Scaffolding.Internal.Services.IFileSystem (#…
Browse files Browse the repository at this point in the history
…3107)

Co-authored-by: Deep Choudhery <[email protected]>
  • Loading branch information
github-actions[bot] and deepchoudhery authored Dec 3, 2024
1 parent 0ec70e8 commit 51866dd
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,12 @@ public async Task AddFileAsync(string outputPath, Stream sourceStream)
await sourceStream.CopyToAsync(writeStream);
}
}

public void CreateDirectoryIfNotExists(string dirPath)
{
if (!DirectoryExists(dirPath))
{
CreateDirectory(dirPath);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ public void CreateIfNotExists()
{
if (!Exists())
{
if (!_fileSystem.DirectoryExists(_dotnetUserProfileFolderPath))
{
_fileSystem.CreateDirectory(_dotnetUserProfileFolderPath);
}

_fileSystem.CreateDirectoryIfNotExists(_dotnetUserProfileFolderPath);
_fileSystem.WriteAllText(SentinelPath, string.Empty);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public interface IFileSystem
{
bool FileExists(string path);

void CreateDirectoryIfNotExists(string dirPath);

bool DirectoryExists(string dirPath);

void CreateDirectory(string dirPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ public override Task<bool> ExecuteAsync(ScaffolderContext context, CancellationT
{
_logger.LogInformation($"Adding file '{FileName}'...");

if (!_fileSystem.DirectoryExists(destinationDirectory))
{
_fileSystem.CreateDirectory(destinationDirectory);
}

_fileSystem.CreateDirectoryIfNotExists(destinationDirectory);
_fileSystem.CopyFile(fileToCopy, destinationFilePath, overwrite: false);
_logger.LogInformation("Done");
return Task.FromResult(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,15 @@ private void EnsureFolderLayout(AreaStepSettings stepSettings)
}

var areaBasePath = Path.Combine(basePath, "Areas");
if (!_fileSystem.DirectoryExists(areaBasePath))
{
_fileSystem.CreateDirectory(areaBasePath);
}
_fileSystem.CreateDirectoryIfNotExists(areaBasePath);

var areaPath = Path.Combine(areaBasePath, stepSettings.Name);
if (!_fileSystem.DirectoryExists(areaPath))
{
_fileSystem.CreateDirectory(areaPath);
}
_fileSystem.CreateDirectoryIfNotExists(areaPath);

foreach (var areaFolder in AreaFolders)
{
var path = Path.Combine(areaPath, areaFolder);
if (!_fileSystem.DirectoryExists(path))
{
_fileSystem.CreateDirectory(path);
}
_fileSystem.CreateDirectoryIfNotExists(path);
}

_logger.LogInformation("Done");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ private bool InvokeDotnetNew(DotnetNewStepSettings stepSettings)
OutputFolders.TryGetValue(stepSettings.CommandName, out var folderName))
{
outputDirectory = Path.Combine(outputDirectory, folderName);
if (!_fileSystem.DirectoryExists(outputDirectory))
{
_fileSystem.CreateDirectory(outputDirectory);
}
_fileSystem.CreateDirectoryIfNotExists(outputDirectory);
}

var projectName = Path.GetFileNameWithoutExtension(stepSettings.Project);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ private bool InvokeDotnetNew(EmptyControllerStepSettings settings)
if (!string.IsNullOrEmpty(outputDirectory))
{
outputDirectory = Path.Combine(outputDirectory, "Controllers");
if (!_fileSystem.DirectoryExists(outputDirectory))
{
_fileSystem.CreateDirectory(outputDirectory);
}
_fileSystem.CreateDirectoryIfNotExists(outputDirectory);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ public bool AddTool(string toolName)

private void EnsureManifestDirectory()
{
if (!_fileSystem.DirectoryExists(GetToolManifestDirectory()))
{
_fileSystem.CreateDirectory(GetToolManifestDirectory());
}
_fileSystem.CreateDirectoryIfNotExists(GetToolManifestDirectory());
}

public ScaffoldManifest GetManifest()
Expand Down

0 comments on commit 51866dd

Please sign in to comment.